Implicit conversion with help of alias this doesn't work if the aliased symbol is a property (or just nullary) function. The following code doesn't compile:
--------------------
void main()
{
S s;
int[] conv = s; // (4)
}
struct S
{
@property int[] get() { return [1,2,3]; }
alias get this;
}
--------------------
% dmd -o- -c test.d
test.d(4): Error: cannot implicitly convert expression (s) of type S to int[]
--------------------
The repro code compiles fine if 'get' is a variable.
Comment #1 by rsinfu — 2010-10-21T10:07:27Z
Created attachment 789
Patch against dmd r725, fixes implicitConvTo()
implicitConvTo() of TypeStruct and TypeClass don't deal with functions, and just tests convertion from function type to value type (then fails). The attached patch fixes the problem by adding a special check for functions. Passed dmd/druntime/phobos tests.