Bug in D type inferencing

Patrick Schluter via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 2 00:39:01 PDT 2016


On Saturday, 2 July 2016 at 01:20:35 UTC, Hiemlick Hiemlicker 
wrote:
> public struct Foo
> {
> 	public void Create(T)(uint delegate(T) c, T param)
> 	{	
> 	}
> }
>
> Foo f;
>
> f.Create((x) { }, "asdf");

I'm a D noob so take it with a very big grain of salt, but I 
think that expression is wrong already on the level of the 
syntax. In your expression x doesn't have any type, neither 
explicit nor deduced. I suppose that something like that could 
work:

f.Create((auto x) { }, "asdf");  // verbose syntax

>
> cannot deduce arguments compiler error.
>
> Surely D can figure out that T is a string?
>
> If one simply changes this to
>
> public struct Foo(T)
> {
> 	public void Create(uint delegate(T) c, T param)
> 	{	
> 	}
> }
>
> and
>
> Foo!string f;
>
> everything works.
>
> The second parameter is a string so why not infer that T is a 
> string?
>
> Also, if one does
>
> f.Create((string x) { }, "asdf");

Here x has a type and the definition is syntactically correct.

>
> Then it works. Seems like a blatant limitation in D's type 
> inferencing system.




More information about the Digitalmars-d mailing list