Thread overview
[Issue 17477] DMD error message for delegate with wrong attributes is very confusing
Jun 07, 2017
Eyal
Jul 21, 2017
Vladimir Panteleev
Jul 21, 2017
Vladimir Panteleev
Dec 17, 2022
Iain Buclaw
May 11, 2023
RazvanN
May 11, 2023
Eyal
Aug 19, 2023
Nick Treleaven
Aug 23, 2023
Eyal
Aug 23, 2023
Nick Treleaven
Aug 23, 2023
Eyal
June 07, 2017
https://issues.dlang.org/show_bug.cgi?id=17477

Eyal <eyal@weka.io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--
July 21, 2017
https://issues.dlang.org/show_bug.cgi?id=17477

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--
July 21, 2017
https://issues.dlang.org/show_bug.cgi?id=17477

Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=10602

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=17477

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
May 11, 2023
https://issues.dlang.org/show_bug.cgi?id=17477

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
This code now compiles because the compiler does inference for function literals.

--
May 11, 2023
https://issues.dlang.org/show_bug.cgi?id=17477

Eyal <eyal@weka.io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WORKSFORME                  |---

--- Comment #2 from Eyal <eyal@weka.io> ---
It is true that this *specific* example now compiles, but if you extract g() to the global scope it shows the problem again:

void f(void delegate(int) nothrow dlg) {}

void g(int x) {}

void main() {
    f((x){ g(x); });
}

  Error: function `testfuncliteral.f(void delegate(int) nothrow dlg)` is not
  callable using argument types `(void)`
         cannot pass argument `__lambda1` of type `void` to parameter `void
delegate(int) nothrow dlg`

--
August 19, 2023
https://issues.dlang.org/show_bug.cgi?id=17477

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #3 from Nick Treleaven <nick@geany.org> ---
> This is wrong, as the argument type is not (void).

The type of a template is void. A lambda without parameter types is a template. When a template lambda doesn't implicitly convert to the expected parameter type, it's not established what the type of the implicitly instantiated lambda is, as it failed to instantiate.

> It is also very difficult to figure out what is wrong with this program from this error (when the code is far more complicated).

The fix for issue #10602 gives:

/home/nick/old/lambdaarg.d(16): Error: function `lambdaarg.f(void delegate(int)
nothrow dlg)` is not callable using argument types `(void)`
/home/nick/old/lambdaarg.d(16):        cannot implicitly convert expression
`__lambda2` of type `void delegate(int x) @system` to `void delegate(int)
nothrow`

Note the inferred argument type that the compiler tried on the second line.

--
August 23, 2023
https://issues.dlang.org/show_bug.cgi?id=17477

--- Comment #4 from Eyal <eyal@weka.io> ---
With the fix for issue #10602 - it sounds much better, though even then I don't think the error should say:

  function `lambdaarg.f(void delegate(int) nothrow dlg)` is not callable using
argument types `(void)`

but rather:

  function `lambdaarg.f(void delegate(int) nothrow dlg)` is not callable using
given template, as it failed to instantiate:

And this is much clearer direction for the programmer to read the actual problem on the next line.

--
August 23, 2023
https://issues.dlang.org/show_bug.cgi?id=17477

--- Comment #5 from Nick Treleaven <nick@geany.org> ---
In this case, yes. But the first line is supposed to show all the argument types passed to the function. E.g. when there's more than one argument.

--
August 23, 2023
https://issues.dlang.org/show_bug.cgi?id=17477

--- Comment #6 from Eyal <eyal@weka.io> ---
Then perhaps instead of "void" it is better to spell out "template instantiation failure, see below" as the type itself.

Verbose, maybe, but clearer how to progress

--