Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Apr 15, 2021

This is blocking: dlang/phobos#7766

@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
21828 normal Using enum of struct (containing another enum) before its declaration fails

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12437"

@BorisCarvajal
Copy link
Member

@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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

@BorisCarvajal BorisCarvajal Apr 15, 2021

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.

Copy link
Contributor

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.

@RazvanN7 RazvanN7 closed this Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review:Blocking Other Work review and pulling should be a priority Severity:Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants