Bug 9627 – Not good enough error messages in some cases when using UFCS

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-03-01T12:48:00Z
Last change time
2013-04-26T04:18:14Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-03-01T12:48:01Z
I tag this as "enhancement" because I don't know if there is a way to solve this problem. This program has a bug: import std.stdio, std.string, std.algorithm, std.range; void main() { auto data = "Given$a$txt$file$of$many$lines,$where$fields$within$a$line$ are$delineated$by$a$single$'dollar'$character,$write$a$program that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$ column$are$separated$by$at$least$one$space. Further,$allow$for$each$word$in$a$column$to$be$either$left$ justified,$right$justified,$or$center$justified$within$its$column." .splitLines.map!q{ a.chomp("$").split("$") }; int[int] maxWidths; foreach (line; data) foreach (i, word; line) maxWidths[i] = max(maxWidths.get(i, 0), word.length); foreach (just; [&leftJustify!string, &center!string, &rightJustify!string]) foreach (line; data) writefln("%-(%s %)", iota(line.length) .map!(i => just(word, maxWidths[i], ' '))); } DMD2.063alpha gives just this error message: temp.d(20): Error: no property 'map' for type 'Result' Can you spot the problem? If you add a () after the call to map: foreach (just; [&leftJustify!string, &center!string, &rightJustify!string]) foreach (line; data) writefln("%-(%s %)", iota(line.length) .map!(i => just(word, maxWidths[i], ' '))()); } It gives a large amount of error messages, but the first error message shows you clearly what's the problem: temp.d(21): Error: undefined identifier word ...\dmd2\src\phobos\std\algorithm.d(404): Error: template instance temp.main.__lambda2!(uint) error instantiating ... temp.d(20): Error: template instance std.stdio.writefln!(string,MapResult!(__lambda2, Result)) error instantiating Lately I have started to omit the () in UCFS (according to this: http://article.gmane.org/gmane.comp.lang.d.phobos/7222 ) and I am seeing several similar situations with insufficient error messages, like that. Is it possible for DMD to improve its error messages in similar situations?
Comment #1 by andrej.mitrovich — 2013-03-02T08:01:50Z
Comment #2 by k.hara.pg — 2013-04-26T04:18:14Z
This issue is solved in 2.063.