October 14, 2020 [Issue 21308] New: error message for using to without importing std.conv is missing suggested import | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21308 Issue ID: 21308 Summary: error message for using to without importing std.conv is missing suggested import Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: diagnostic Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: schveiguy@yahoo.com 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. -- |
Copyright © 1999-2021 by the D Language Foundation