Fix Issue 9701 - allow UDAs to be attached to enum values#8319
Fix Issue 9701 - allow UDAs to be attached to enum values#8319JinShil wants to merge 1 commit intodlang:masterfrom JinShil:fix_9701
Conversation
|
Thanks for your pull request, @JinShil! 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#8319" |
| { | ||
| value0, | ||
| @("uda1") value1, | ||
| @("uda2") @("uda3") value2, |
There was a problem hiding this comment.
Should be a test with the @uda syntax as well.
| super(loc, TOK.variable, __traits(classInstanceSize, VarExp), var, hasOverloads); | ||
| //printf("VarExp(this = %p, '%s', loc = %s)\n", this, var.toChars(), loc.toChars()); | ||
| //if (strcmp(var.ident.toChars(), "func") == 0) assert(0); | ||
| this.type = var.type; |
There was a problem hiding this comment.
This was needed to prevent semantic from printing a deprecation multiple times. I used the common pattern to check for type to see if semantic has already been run. This also required some refactoring of the expression semantic visitor for VarExp.
There was a problem hiding this comment.
Is this really the correct fix?
There was a problem hiding this comment.
I'm not 100% sure, but if you search expressionsem.d for if (e.type) you will see it is a common idiom. The expression classes don't seem to have a flag indicating whether or not semantic has been run, so it looks like the type property is (ab)used for that.
It doesn't work at the moment anyway because there are other places in the code that don't call expressionSemantic on the VarExp class, so I need to submit a separate PR to remedy that. I worked on it all day today, and it's proving to be quite difficult.
If I don't do this, then a deprecation message is printed every type VarExp.expressionSemantic is run, and that's suboptimal. I need some way to know whether or it has already been run, and the dominating idiom for that seems to be if (e.type) in the semantic visitor functions.
src/dmd/expressionsem.d
Outdated
| VarDeclaration v = ve.var.isVarDeclaration(); | ||
| if (v && ve.checkPurity(sc, v)) | ||
| return setError(); | ||
| exp.e1 = ve.expressionSemantic(sc); |
There was a problem hiding this comment.
Because we removed setting type in VarExp's constructor. See https://github.com/dlang/dmd/pull/8319/files#r192327829
|
This is currently held up on a problem with the |
| @uda5 @uda6 value4, | ||
| @("uda7") @uda8 value5, | ||
| @uda9 @("uda10") value6, | ||
| deprecated value7 |
There was a problem hiding this comment.
Please add a test for deprecated with a message as well, i.e. deprecated("foo").
|
I'm closing this. My frustration with D has hit a new high, and I need to walk away for a while. |
|
@JinShil Hi. Why do you closed this PR? Are there any troubles in implementation? |
|
You may call |
Hi @IgorStepanov, Yes, there is one fundamental issue that I can't find a solution for. The semantic pass for I asked for help on the forum but never received a response. Edit: If you think you can fix this, please adopt this PR and let's bring it to completion. |
|
@JinShil we may add the field with flag only for attribute errors. Ensure that this field properly copies in |
Because we want the error message at the usage site, not the declaration site.
👍 |
This is a reboot of #6161
I've also added the ability to mark enum members as
deprecatedand@disabled.It was decided a while ago that a proper implementation would be accepted without a DIP. Here's the forum announcement: https://forum.dlang.org/post/gcgtotrhuirhcvvbxrfm@forum.dlang.org
This only implements the feature for enum members. For function arguments, see #7576