Bug 21308 – error message for using to without importing std.conv is missing suggested import

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-10-14T15:30:24Z
Last change time
2024-12-13T19:12:05Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#19802 →

Comments

Comment #0 by schveiguy — 2020-10-14T15:30:24Z
The compiler has several symbols that it suggests imports for. std.conv.to is included in the list here: https://github.com/dlang/dmd/blob/aef4ac2a0901e4f2bf6cefe4c69a9c4c22cce76d/src/dmd/imphint.d#L78 However, when calling the function as a function, with an explicit template instantiation, the compiler does not identify the problem of importing std.conv: void main() { auto x = to!string(1); } Error: template instance `to!string` template `to` is not defined However, if I try to use to without an explicit instantiation, or I use UFCS to call it, it does report the error message: void main() { auto x = to(1); } Error: to is not defined, perhaps import std.conv; is needed? or void main() { auto x = 1.to!string; } Error: no property to for type int, perhaps import std.conv; is needed? I would expect the suggestion on the first case as well. Note that this is a problem with all such suggestions for that mechanism, not just to. It's just that to is more often instantiated in this way. The criteria seems to be that it needs to be a template instantiation that is not written as a member. e.g.: void main() { writefln!"hello, %s"("world"); } Error: template instance writefln!"hello, %s" template writefln is not defined All these should suggest the import.
Comment #1 by robert.schadek — 2024-12-13T19:12:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19802 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB