-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Issue 21828 - Using enum of struct (containing another enum) before its declaration fails #12437
Conversation
…re its declaration fails
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12437" |
|
@RazvanN7: you beat me for 5 minutes, I was about to pull my version. Still going to do it because I resolved in another way. |
| @@ -363,6 +363,9 @@ private void resolveHelper(TypeQualified mt, const ref Loc loc, Scope* sc, Dsymb | |||
| s = sm.toAlias(); | |||
| } | |||
|
|
|||
| if (auto ed = s.isEnumDeclaration()) | |||
| s.dsymbolSemantic(sc); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds an odd special case, #12438 seems to be the more general approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit that doing semantic here isn't ideal, however, I think it's better to analyze the enum in its entirety. In contrast #12438 does semantic on the first member only and defers the rest for later.
That being said, I have no problem conceding as long as the issue is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit that doing semantic here isn't ideal, however, I think it's better to analyze the enum in its entirety. In contrast #12438 does semantic on the first member only and defers the rest for later.
Why? the spec says clearly
- If the EnumBaseType is not explicitly set, and the first EnumMember has an AssignExpression, it is set to the type of that AssignExpression. Otherwise, it defaults to type int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A self-contained solution as a compromise of both PR's:
diff --git a/src/dmd/denum.d b/src/dmd/denum.d
index 267fb4f01..9886d85dc 100644
--- a/src/dmd/denum.d
+++ b/src/dmd/denum.d
@@ -342,6 +342,8 @@ extern (C++) final class EnumDeclaration : ScopeDsymbol
Loc locx = loc.isValid() ? loc : this.loc;
memtype = memtype.typeSemantic(locx, _scope);
}
+ else
+ dsymbolSemantic(this, _scope);
}
if (!memtype)
{Allthough this is slightly less capable w.r.t. to deep forward references.
This is blocking: dlang/phobos#7766