[Issue 9627] New: Not good enough error messages in some cases when using UCFS

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 1 12:48:02 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9627

           Summary: Not good enough error messages in some cases when
                    using UCFS
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-03-01 12:48:01 PST ---
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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list