D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11000 - Static field type inference failure
Summary: Static field type inference failure
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-09-09 16:56 UTC by daniel
Modified: 2020-07-04 16:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description daniel 2013-09-09 16:56:30 UTC
```struct Foo {
	int a;

	this(int a) { this.a = a; } // reason for fail

	static immutable bar = Foo(1); // fails
//	static immutable Foo bar = Foo(1); // works
}

void main() {
	auto a = Foo.bar;
}

```

The code above should compile, instead: `test.d(6): Error: cannot create a struct until its size is determined`.

Remove the explicit constructor at line 4, and line 6 compiles.

Add the explicit type onto the type declaration (as on line 7), and it will work without removing the explicit constructor.
Comment 1 Andrej Mitrovic 2013-09-09 18:03:19 UTC
This looks like a dupe I've seen before. Reduced:

-----
struct Foo
{
    this(int) {}
    static f = Foo(1);
}

void main() { }
-----
Comment 2 basile-z 2020-07-04 16:50:58 UTC
since 2.068.2 ok