Skip to content

Fix Issue 9701 - allow UDAs to be attached to enum values#8404

Merged
dlang-bot merged 1 commit intodlang:masterfrom
IgorStepanov:uda-enum
Jun 27, 2018
Merged

Fix Issue 9701 - allow UDAs to be attached to enum values#8404
dlang-bot merged 1 commit intodlang:masterfrom
IgorStepanov:uda-enum

Conversation

@IgorStepanov
Copy link
Contributor

Reboot of #8319
@JinShil @jacob-carlborg Let finish it.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @IgorStepanov! 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 annotated coverage diff directly on GitHub with CodeCov's browser extension
  • 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
9701 normal UDAs cannot be attached to enum values.

Testing this PR locally

If 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#8404"

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! I hope that the third attempt works 👍

src/dmd/denum.d Outdated
Type origType;

EnumDeclaration ed;
bool isdeprecated;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: We now have an official D style which we try to follow for new variables.
So this would be isDeprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base class Dsymbol already has a virtual method isDeprecated(). And some classes e.g. AggregateDeclaration has a field isdeprecated, which is returned by overridden method isDeprecated().
Maybe stay it as is?

Copy link
Contributor

@wilzbach wilzbach Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess _deprecated or _isDeprecated or isDeprecatedEnum would be better than having a symbol which only differences in the spelling?
BTW isdeprecated is only set once and never looked at, which looks a bit suspicious.

Copy link
Contributor

@JinShil JinShil Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW isdeprecated is only set once and never looked at, which looks a bit suspicious.

Yeah, may be a leftover of some debugging I was doing. @IgorStepanov, please investigate if it's actually needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've just removed it:)

*/
extern (C++) final class VarExp : SymbolExp
{
bool hasCheckedAttrs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little naughty, but I don't know of any other solution, and it'd be a shame to hold up this feature on such a minor problem, so OK, let's do it. I do, however, suggest adding a comment explaining why this exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@JinShil
Copy link
Contributor

JinShil commented Jun 26, 2018

We probably need to update the language spec also. I'll try to get to it later, but I won't mind if someone beats me to it.

@IgorStepanov IgorStepanov force-pushed the uda-enum branch 2 times, most recently from ee289ed to da07d98 Compare June 26, 2018 01:06
@IgorStepanov
Copy link
Contributor Author

BTW, What purpose of astbase module and classes. Looks like astbase.Dsymbol.deprecatedDeclaration hasn't used anywhere. Maybe we should skip dd parameter of constructor?

@JinShil
Copy link
Contributor

JinShil commented Jun 26, 2018

BTW, What purpose of astbase module and classes. Looks like astbase.Dsymbol.deprecatedDeclaration hasn't used anywhere. Maybe we should skip dd parameter of constructor?

Keep in mind that I had been playing with that code for a very long time, trying many different things to work through the problem. If you find that the DeprecatedDeclaration is not needed, then just remove it.

@wilzbach
Copy link
Contributor

wilzbach commented Jun 26, 2018

BTW, What purpose of astbase module and classes.

AstBase is used nowhere in DMD. It was an attempt by @RazvanN7 to separate the AST nodes and create a pure "data" layer.
However, the switch to AstBase has never been made though I don't recall the exact reasons (I think it had sth. to do with the proposal needing too many templates).
See also:

@IgorStepanov
Copy link
Contributor Author

Keep in mind that I had been playing with that code for a very long time, trying many different things to work through the problem. If you find that the DeprecatedDeclaration is not needed, then just remove it.

astbase.EnumMember.__ctor should have the same signature with denum.EnumMember.__ctor because they both are used in Parser(AST).
I may just ignore dd parameter in astbase.EnumMember.__ctor, but in can be needed in astbase.EnumMembe in future.

@JinShil
Copy link
Contributor

JinShil commented Jun 26, 2018

but in can be needed in astbase.EnumMembe in future.

I suggest adhering to the YAGNI principle. In other words, if it's not used, remove it from both constructors.

@IgorStepanov
Copy link
Contributor Author

@JinShil

remove it from both constructors.

It needed in denum.EnumMember.__ctor and isn't needed in astbase.EnumMember.__ctor.
Thus it should be in constructor but may be ignored in astbase.EnumMember.

@IgorStepanov
Copy link
Contributor Author

may be ignored in astbase.EnumMember

Done

{
// Semantic can be called many times for a one expression.
// This field need to ensure that deprecation message will be printed only one time.
bool hasCheckedAttrs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes for proper English grammar:

// Semantic can be called multiple times for a single expression.
// This field is needed to ensure the deprecation message will be printed only once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@JinShil
Copy link
Contributor

JinShil commented Jun 26, 2018

It looks good to me. I would like to hear from @RazvanN7 about the discrepancy with ASTBase.

@JinShil
Copy link
Contributor

JinShil commented Jun 26, 2018

Spec PR: dlang/dlang.org#2396

*/
extern (C++) final class VarExp : SymbolExp
{
// Semantic can be called many times for a one expression.
Copy link
Contributor

@jacob-carlborg jacob-carlborg Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a Ddoc comment. All public or protected symbols should have a documentation, i.e. a Ddoc comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,24 @@
D now supports attributes on enum members

Copy link
Contributor

@jacob-carlborg jacob-carlborg Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps explicitly list the supported attributes since it's only three (counting UDAs as one) and to avoid any confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@jacob-carlborg jacob-carlborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few minor comments.

@IgorStepanov
Copy link
Contributor Author

@JinShil @jacob-carlborg All comments resolved. Any other objections?

@jacob-carlborg
Copy link
Contributor

It looks good to me. I would like to hear from @RazvanN7 about the discrepancy with ASTBase.

As far as I understand, ASTBase was introduced to allow using the parser without the rest of the frontend. Using the rest of the frontend as a library caused some problems. Those are fixed and the full frontend is available as a library. I don't think there's a need for ASTBase.

Copy link
Contributor

@jacob-carlborg jacob-carlborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve this and if there's a need to update ASTBase we can do that in a followup PR.

@dlang-bot dlang-bot merged commit 972ea45 into dlang:master Jun 27, 2018
@IgorStepanov
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants