On Tuesday, 23 February 2016 at 12:43:42 UTC, Kagamin wrote:
Don't we already have implicit conversions with alias this, so what's the deal?

The deal is you can't have implicit construction like:
A a = 5; // Error
a = 5 // okay

struct A { int i; alias i this; }
void f(int i){}
void f(string s){}
void g(A a){ f(a); } //what's called?

f(int) will be called. But problem here is the opposite: try calling g() with an int argument (like 5) and compiler won't let you.


import std.stdio;

struct A { int i; alias i this;}
void f(int i){writeln("int");}
void f(A a){writeln("A");}

void g(A a){ f(a); }

void main()
{
    g(A());
}

Above code prints "A". I would expect it to be an ambiguity error. Not sure if I should file a bug report?

Reply via email to