Bug 11444 – Better error messages for Phobos ranges used without bang !
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-05T07:39:00Z
Last change time
2013-11-05T13:21:53Z
Keywords
diagnostic
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-11-05T07:39:06Z
This is wrong code:
import std.stdio, std.algorithm;
void main() {
"123".map(d => d - '0').writeln;
}
dmd 2.064beta gives the error messages:
test.d(3): Error: template std.algorithm.map does not match any function template declaration. Candidates are:
...\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(398): std.algorithm.map(fun...) if (fun.length >= 1)
test.d(3): Error: template std.algorithm.map(fun...) if (fun.length >= 1) cannot deduce template function from argument types !()(string, void)
The mistake is in the map, it should be "map!(...)". Range-based code that uses map, filter and other similar functions is becoming common, so I suggest to add some euristics to the D front-end to generate better error messages for common Phobos templates that are used without the "!", something like:
test.d(3): Error: template std.algorithm.map does not match any function template. Did you miss a "!"?
Comment #1 by andrej.mitrovich — 2013-11-05T13:21:53Z
*** This issue has been marked as a duplicate of issue 9179 ***