www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13869] New: Not good error message with not compatible lambda

https://issues.dlang.org/show_bug.cgi?id=13869

          Issue ID: 13869
           Summary: Not good error message with not compatible lambda
                    template argument
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

void foo(double function(double)  safe,
         double function(double)  safe) {}
void main() {
    enum real y = 1;
    foo(x => double(y), x => x); // line 5, OK
    foo(x => y, x => x);         // line 6, Error
}


dmd 2.067alpha gives:

test.d(6,8): Error: function test.foo (double function(double)  safe _param_0,
double function(double)  safe _param_1) is not callable using argument types
(void, void)


The line 5 is correct because the two given template lambdas match the
functions in the 'foo' signature. While the line 6 is not correct because the
first lambda template returns a real, that is not compatible with a function
that returns a double.

In both lines the second lambda template is correct, but the error message
gives a "(void, void)", so if the first lambda template doesn't match, the
second isn't even tried. This doesn't help me find what of the two lambdas is
the wrong one.

And even for the first lambda template, giving just a "void" when the given
lambda template returns a real instead of a double seems excessive.

So ideally I'd like an error message more like:

test.d(6,8): Error: function test.foo(double function(double)  safe _param_0,
double function(double)  safe _param_1) is not callable using argument types
(real function(double)  safe, double function(double)  safe), the first
argument doesn't match

--
Dec 16 2014