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
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.
https://github.com/D-Programming-Language/dmd/pull/4457
*** Issue 5223 has been marked as a duplicate of this issue. ***
*** Issue 9397 has been marked as a duplicate of this issue. ***
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a7bdba471111f09f7dba2fbbc6a3d91d8ba110e7 fix Issue 6766 - Forward reference error for default struct/class arguments https://github.com/D-Programming-Language/dmd/commit/b675901392ad8e6873e47f77172e6e36f49aa351 Merge pull request #4457 from 9rnsr/fix6766 Issue 6766 - Forward reference error for default struct/class arguments
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7d3e1fb463f71b6332512ffb094f2285e2b07825 Move issue 6766 test case to compilable/testfwdref.d
*** Issue 14678 has been marked as a duplicate of this issue. ***
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a7bdba471111f09f7dba2fbbc6a3d91d8ba110e7 fix Issue 6766 - Forward reference error for default struct/class arguments https://github.com/D-Programming-Language/dmd/commit/b675901392ad8e6873e47f77172e6e36f49aa351 Merge pull request #4457 from 9rnsr/fix6766 https://github.com/D-Programming-Language/dmd/commit/7d3e1fb463f71b6332512ffb094f2285e2b07825 Move issue 6766 test case to compilable/testfwdref.d