Thread overview
[Issue 17263] Issue diagnostic if mandatory template parameter is missing
Mar 17, 2017
Jonathan M Davis
Mar 18, 2017
Vladimir Panteleev
Mar 20, 2017
Lewis
Aug 01, 2019
Jonathan M Davis
Aug 12, 2019
Les De Ridder
Nov 18, 2022
RazvanN
Nov 18, 2022
Ali Cehreli
Nov 18, 2022
RazvanN
Nov 18, 2022
Ali Cehreli
Nov 18, 2022
RazvanN
March 17, 2017
https://issues.dlang.org/show_bug.cgi?id=17263

Jonathan M Davis <issues.dlang@jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang@jmdavisProg.co
                   |                            |m

--- Comment #1 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
Yeah, this is one of those that's usually surprisingly hard to figure out. I usually end up doing a lot of examination of template constraints before I figure out that I simply forgot the !. It's a lot more obvious in this example, because it's short, but one you start chaining templates or having complicated predicates, it quickly becomes non-obvious that the ! is missing.

--
March 18, 2017
https://issues.dlang.org/show_bug.cgi?id=17263

Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |thecybershadow@gmail.com

--
March 20, 2017
https://issues.dlang.org/show_bug.cgi?id=17263

Lewis <musicaljelly@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |musicaljelly@gmail.com

--- Comment #2 from Lewis <musicaljelly@gmail.com> ---
+1

I have made this mistake many times, and spent an embarrassingly long time trying to deduce the solution each time. A better compiler error would make the fix immediately obvious in these cases.

--
August 01, 2019
https://issues.dlang.org/show_bug.cgi?id=17263

--- Comment #3 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
LOL. I just ran into this issue again, wasted several minutes trying to figure out what was wrong, finally figured it out, and then decided to open an enhancement request. But voila, there's already one sitting here, and I commented on it previously. Honestly, I'd guess that this is quite possibly the dmd error message that would provide the most benefit in being improved. Maybe it gets harder to diagnose correctly when there are multiple overloads and they don't all necessarily have the same number of template arguments, but it at least _seems_ like it should be straightforward to figure out that the problem is probably the lack of a ! and indicate as much to the programmer, even if it's just a suggestion rather than an indicator that that's definitely the problem.

--
August 12, 2019
https://issues.dlang.org/show_bug.cgi?id=17263

Les De Ridder <dlang@lesderid.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang@lesderid.net

--
November 18, 2022
https://issues.dlang.org/show_bug.cgi?id=17263

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
Hi Ali,

Now the diagnostic is:

test2.d(4): Error: none of the overloads of template
`std.algorithm.iteration.map` are callable using argument types `!()(int[],
void)`
/home/razvann/Dlang/dmd/generated/linux/release/64/../../../../../phobos/std/algorithm/iteration.d(436):
       Candidate is: `map(fun...)`
  with `fun = ()`
  must satisfy the following constraint:
`       fun.length >= 1`


I know it's not what you expected but isn't this better?

I am afraid that the actual error ("You forgot `!`") cannot be outputted because when the template is instantiated we are in the semantic phase where we no longer know whether the ! was present or not. In other words, we cannot know just by looking at the AST if the user provided template instance was `[1, 2].map(i => i);` or `[1, 2].map!()(i => i);`. So. I think that this is the best we could probably do in this case.

--
November 18, 2022
https://issues.dlang.org/show_bug.cgi?id=17263

--- Comment #5 from Ali Cehreli <acehreli@yahoo.com> ---
Thank you!

--
November 18, 2022
https://issues.dlang.org/show_bug.cgi?id=17263

--- Comment #6 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Ali Cehreli from comment #5)
> Thank you!

You are welcome! OK to close this?

--
November 18, 2022
https://issues.dlang.org/show_bug.cgi?id=17263

--- Comment #7 from Ali Cehreli <acehreli@yahoo.com> ---
If you are asking me, the reporter, I am happy with your explanation why it can't be better. I wouldn't mind closing.

--
November 18, 2022
https://issues.dlang.org/show_bug.cgi?id=17263

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

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

--