Comment #0 by andrej.mitrovich — 2011-10-04T09:35:05Z
void test(Bar bar = Bar(1)) { }
struct Bar
{
this(int x) { }
}
void main() { }
Error: more initializers than fields of Bar
This also affects structs and classes that have methods with default arguments that call ctors of typeof(this):
class Foo
{
this(int x) { }
void test(Foo foo = new Foo(1)) { }
}
struct Bar
{
this(int x) { }
void test(Bar bar = Bar(1)) { }
}
void main() {}
test.d(4): Error: no constructor for Foo
test.d(10): Error: more initializers than fields of Bar
Comment #1 by hsteoh — 2014-11-06T01:29:32Z
Tested on git HEAD, the first case now works; the second case gives the error message:
------
test.d(4): Error: no constructor for Foo
test.d(10): Error: cannot create a struct until its size is determined
------
So looks like the bug is partially fixed, but not quite there yet.