www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21308] New: error message for using to without importing


          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:


However, when calling the function as a function, with an explicit template
instantiation, the compiler does not identify the problem of importing

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?


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.


void main()
   writefln!"hello, %s"("world");

Error: template instance writefln!"hello, %s" template writefln is not defined

All these should suggest the import.

Oct 14 2020