-
-
Notifications
You must be signed in to change notification settings - Fork 610
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 21785 - Improve error messages for opaque enums #12325
Conversation
|
Well we don't know the enum definition, so assuming the initializer is its base |
Aren't opaque enums more intended as a strong typedef (e.g. But i guess I'll adapt this PR to create a proper error message. |
Nope, they are just hidden/forward reference types, typically you pass them around by pointer, same as opaque structs. C long and friends are just a special case. |
a600260 to
39175b4
Compare
33d125a to
81268eb
Compare
| static assert(is(E1 e == enum) && is(e == int)); | ||
|
|
||
| enum E2; | ||
| static assert(is(E2 e == enum)); |
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 snippet doesn't involve a forward reference and therefore compiles now.
| if (semanticRun >= PASS.semanticdone) | ||
| error(loc, "is opaque and has no default initializer"); | ||
| else | ||
| error(loc, "forward reference of `%s.init`", toChars()); |
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 line isn't covered because actual forward references crash dmd...
Will open another PR for those errors.
|
Thanks for your pull request and interest in making D better, @MoonlightSentinel! 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#12325" |
81268eb to
f78b5e2
Compare
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.
LGTM. Just a question: What does the error looks like with e.g. enum NoBase; Nobase nb = void; ?
The error messages for default initialized variables of opaque enums
were horrid and contained misleading informations.
This PR removes them by by checking whether semantic was already
run in case of an enum without members.
Some examples:
```d
enum NoBase;
enum WithBase : long;
// Not handled yet
struct S;
enum OpaqueBase : S;
void main()
{
NoBase nb;
WithBase wb;
OpaqueBase ob;
}
```
f78b5e2 to
92d1d59
Compare
|
There is no error because |
The error messages for default initialized variables of opaque enums were horrid and contained misleading informations.
This PR removes them by by checking whether semantic was already run in case of an enum without members.
Some examples: