Bug 9397 – Size error with struct with ctor and self-typed nested enum

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-25T18:53:00Z
Last change time
2015-03-10T15:55:58Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich
Blocks
340
See also
http://d.puremagic.com/issues/show_bug.cgi?id=5460, http://d.puremagic.com/issues/show_bug.cgi?id=6766

Comments

Comment #0 by andrej.mitrovich — 2013-01-25T18:53:53Z
struct S { this(int i) { } int i; enum s = S(0); // L5: fail } void main() { } Error: cannot create a struct until its size is determined This used to be a wrong-code bug (see Issue 8741), but now it's an error.
Comment #1 by sludwig — 2013-02-08T00:56:44Z
Setting to regression, as it works up to v2.061.
Comment #2 by sludwig — 2013-02-08T01:01:58Z
Let me rephrase that. Before this triggered an error, the example worked fine because the constructor call is equivalent to using a struct literal. This special case has allowed me to work around the various issues surrounding self-typed constants. Now with this error all hope for a workaround seems lost.
Comment #3 by clugdbug — 2013-02-08T02:50:50Z
This isn't a regression. It has never worked. (Silently generating wrong code doesn't count as working).
Comment #4 by clugdbug — 2013-02-08T02:56:07Z
"This special case has allowed me to work around the various issues surrounding self-typed constants" s/special case/compiler bug/ You should be specific about what the "various issues" are, and then close this bug.
Comment #5 by sludwig — 2013-02-08T03:22:26Z
While writing an answer I noticed that this can be easily worked around by changing the code to (add an explicit type to the enum): struct S { this(int i) { this.i = i; } int i; enum S s = S(0); } So since I'm now looking at changing a few dozen lines of code to workaround this instead of hundreds or more, and also unglifying the code, this has become much less critical for me personally. Regarding the other bugs in this area, there have been some, including http://d.puremagic.com/issues/show_bug.cgi?id=1800 and some partially related, such as http://d.puremagic.com/issues/show_bug.cgi?id=3801. I didn't find anything that is still open, though. The comment was more about the history of the code construct that is shown here. --- Regarding normal vs. regression, you can also view it this way: The code above is valid and did the right thing, even if just by accident. If the code later does not compile anymore that may not be a regression from a compiler-internal view, but from the outside it is. (I won't argue about this now that there is a workaround, but thats my view on it)
Comment #6 by andrej.mitrovich — 2014-05-01T19:58:04Z
*** Issue 12665 has been marked as a duplicate of this issue. ***
Comment #7 by dlang-bugzilla — 2014-05-01T20:04:58Z
How come the size calculation can't be delayed until that enum value is actually needed? There's no recursive dependencies here, so I think this should juts work.
Comment #8 by dlang-bugzilla — 2014-05-01T20:06:56Z
> Regarding normal vs. regression, you can also view it this way: The code above is valid and did the right thing, even if just by accident. I agree with this. A valid fix which would not qualify as being labeled a regression would be to forbid adding fields after the size has already been queried, i.e. allow such code if the enums occur at the end of the struct.
Comment #9 by smjg — 2014-05-03T00:15:52Z
(In reply to Vladimir Panteleev from comment #7) > There's no recursive dependencies here, so I think this > should juts work. Or even more sensibly, first build the layout of the struct and then do the semantic analysis of enums, methods, etc.
Comment #10 by k.hara.pg — 2015-03-10T15:55:58Z
*** This issue has been marked as a duplicate of issue 6766 ***