Spell checking errors can be hilarious

Steven Schveighoffer schveiguy at gmail.com
Tue Oct 13 13:15:18 UTC 2020


On 10/13/20 4:31 AM, Jacob Carlborg wrote:
> On Monday, 12 October 2020 at 20:46:07 UTC, Steven Schveighoffer wrote:
> 
>> What do you mean? Just add "to" : "std.conv". Is there a problem with it?
> 
> It's already in the list [1], it's been there for two years. 

Wait, why doesn't it work?

void main()
{
     auto x = to!string(1);
}

onlineapp.d(3): Error: template instance to!string template to is not 
defined

> Unfortunately it's not that simple. The current implementation is a very 
> simple mapping of a name to an import. What if there are multiple module 
> level symbols with the same name in Phobos or druntime? Then the 
> compiler will be wrong in some of those cases. Also, take this for example:
> 
> auto too(T, U)(U value)
> {
>      return value;
> }
> 
> void main()
> {
>      auto a = 3.to!string;
> }
> 
> This will result in a compile error:
> 
> Error: no property `to` for type `int`, perhaps `import std.conv;` is 
> needed?

If you look at the "New to Dlang" stream, what happens is it says "Did 
you mean `No`?". So literally what you are asking for it to do (and it 
does do), causes about 30 minutes of fruitless searching. Whereas if it 
had said "perhaps `import std.conv;` is needed?", I think a more 
favorable review might have been the result.

I tested it some more.

1.to!string => Suggests import std.conv
to!string(1) => No template named to.

This seems like a bug to me.

-Steve


More information about the Digitalmars-d mailing list