Struct constructors are disregarded when a struct parameter is constructed out of a default value:
struct S2
{
}
struct S
{
int x;
this(S2 s2)
{
}
void foo(S s = S(S2))
{
}
}
void main()
{
S s;
s.foo(); // error
}
Error: cannot implicitly convert expression (S2()) of type S2 to int.
Comment #1 by samukha — 2010-11-16T09:48:10Z
Even simpler test-case:
struct S
{
this(int x)
{
}
void foo(S s = S(42))
{
}
}
void main()
{
S s;
s.foo(); // error
}
Error: more initializers than fields of S
Comment #2 by andrej.mitrovich — 2012-12-18T12:44:39Z
(In reply to comment #1)
> Even simpler test-case:
This is very similar to Issue 3206.
I think what's probably happening is that the semantic analysis on the call expression in a default argument is done without completing the semantic analysis on the struct/class first.
Comment #3 by andrej.mitrovich — 2013-02-10T09:05:19Z