D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6766 - Forward reference error for default struct/class arguments
Summary: Forward reference error for default struct/class arguments
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
: 5223 9397 14678 (view as issue list)
Depends on:
Blocks: 340
  Show dependency treegraph
 
Reported: 2011-10-04 09:35 UTC by Andrej Mitrovic
Modified: 2015-06-17 21:01 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2011-10-04 09:35:05 UTC
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 hsteoh 2014-11-06 01:29:32 UTC
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.
Comment 3 Kenji Hara 2015-03-06 15:07:46 UTC
*** Issue 5223 has been marked as a duplicate of this issue. ***
Comment 4 Kenji Hara 2015-03-10 15:55:58 UTC
*** Issue 9397 has been marked as a duplicate of this issue. ***
Comment 5 github-bugzilla 2015-03-28 20:19:05 UTC
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
Comment 6 github-bugzilla 2015-03-30 06:10:35 UTC
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
Comment 7 Vladimir Panteleev 2015-06-10 23:17:25 UTC
*** Issue 14678 has been marked as a duplicate of this issue. ***