-
-
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
Issue 12652 - Non-constant hash initializers should have a special-case diagnostic #11598
Conversation
|
Thanks for your pull request and interest in making D better, @adelavais! 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#11598" |
src/dmd/todt.d
Outdated
| */ | ||
| void visitAssocArrayLiteral(AssocArrayLiteralExp e) | ||
| { | ||
| e.error("Associative array literals currently cannot be initialized globally, in structs or in classes; try using 'enum' or a module constructor instead"); |
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 is rather long, the sugession should be a second line using errorSuplemental.
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.
The error message should rather mention that it's impossible to initialize AA at compile time instead of runtime (the difference between [1],[2] and [3],[4]).
(I assume that this distinction should be understandable for non-compiler developers but other suggestions are welcome]
test/fail_compilation/issue12652.d
Outdated
| import std.range; | ||
| import std.stdio; | ||
| import std.traits; |
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.
No phobos in the test suite (it's also unused?)
test/fail_compilation/issue12652.d
Outdated
| string[A] t = [A.x : "aaa", A.y : "bbb"]; | ||
| } | ||
|
|
||
| void main () |
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.
Unnecessary?
test/fail_compilation/issue12652.d
Outdated
|
|
||
| struct S | ||
| { | ||
| string[A] t = [A.x : "aaa", A.y : "bbb"]; |
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.
Might as well add another global AA at module scope.
|
A few suggestion:
|
|
Thank you both for your feedback! I will update the PR as soon as possible. |
|
@adelavais are you still pursuing this? |
Yes, I am. I will try to send a PR over the weekend. |
src/dmd/todt.d
Outdated
| */ | ||
| void visitAssocArrayLiteral(AssocArrayLiteralExp e) | ||
| { | ||
| e.error("Associative array literals currently cannot be initialized globally, in structs or in classes; try using 'enum' or a module constructor instead"); |
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.
Error messages are not capitalized
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.
The error message does not quite make sense. The one from the bug report is better:
Associative array literals currently cannot be used to initialize globals. Try using a module constructor instead.
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.
And remove "currently".
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.
They aren't actually globals, either. They are statically allocated.
…l-case diagnostic
|
@MoonlightSentinel @WalterBright @Geod24 I rebased this and addressed the concerns. Is this ready to go? |
|
cc @dkorpel |
Hello! I am unsure if this is the best error message, but from what I can see the problem is not only for global [0] declaration (like in the issue), I discovered it in a struct [1], and it extends to classes [2] too. There is no error in main or in a function called by main [3].
[0]: https://run.dlang.io/is/RRJOBT
[1]: https://run.dlang.io/is/E53JkC
[2]: https://run.dlang.io/is/2jOMg6
[3]: https://run.dlang.io/is/Q2I4mN