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 7443 - Better diagnostic on wrongly written static constructor #8164
Conversation
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 fetch digger
dub run digger -- build "master + dmd#8164" |
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.
Yes, please make it a deprecation instead of an error. Especially since it was necessary to change a test.
@jacob-carlborg Thanks for the answer. Done. |
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 changelog is required as well, describing the problem and what to do to solve it.
@jacob-carlborg Done. |
{ | ||
static | ||
{ | ||
this() |
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.
Missing semicolon?
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.
Yes, added.
keyword does not have any effect on the constructor. | ||
The solution is to declare the constructor outside the | ||
static block either as a normal constructor or a static | ||
one (`static this()`). |
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.
Why the indentation for many of the paragraphs?
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.
Fixed the indentation. I thought it looked nicer that way
1c0c3f5
to
ccd921a
Compare
Same question here, do we need a spec update? |
I don't think so : https://dlang.org/spec/class.html#static-constructor . The spec does not explicitly say it is an error, just that it's not a static constructor. At most, the example in the spec could be updated to pinpoint that the code will issue an error once the deprecation is over. |
Ok, so the spec was missing this. Or rather there was a bug in the compiler and shouldn't have worked in the first place. |
LGTM 👌. Going to leave this open a bit longer for others to get a chance to look as well. |
From the spec:
Why does a static constructor need to be given extra special treatment? Can't the compiler be fixed to recognize that the constructor is in a static block and define it as a static constructor instead of emitting an error? |
Although I might admit that this is not the best solution, I think that these are the 2 reasons why the static
|
@JinShil changing behavior from one working semantics to a different working semantics is the most perilous so we want to avoid that. |
This should probably go through a deprecation cycle. Opinions?