-
Notifications
You must be signed in to change notification settings - Fork 259
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
Feat: {:only}
attribute for members
#4075
Conversation
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 is a great feature to have. My comments are just minor wording changes and slight reductions in redundancy.
mitigation: "Remove the [{:only}] attribute", | ||
mitigationIETF: "Must remove the [{:only}] attribute", | ||
mitigation: "Remove the [{:only}] attribute.", | ||
mitigationIETF: "Must remove the [{:only}] attribute.", |
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.
mitigationIETF: "Must remove the [{:only}] attribute.", | |
mitigationIETF: "MUST remove the [{:only}] attribute.", |
That's the standard IETF way of writing obligatory requirements.
public static readonly AssumptionDescription MemberOnly = new( | ||
issue: "Member has explicit temporary [{:only}] attribute.", | ||
mitigation: "Remove the [{:only}] attribute.", | ||
mitigationIETF: "Must remove the [{:only}] attribute.", |
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.
mitigationIETF: "Must remove the [{:only}] attribute.", | |
mitigationIETF: "MUST remove the [{:only}] attribute.", |
Source/DafnyCore/AST/MemberDecls.cs
Outdated
@@ -105,6 +106,19 @@ public MemberDecl(RangeToken rangeToken, Name name, bool hasStaticKeyword, bool | |||
} | |||
|
|||
public virtual IEnumerable<Expression> SubExpressions => Enumerable.Empty<Expression>(); | |||
|
|||
public bool HasOnlyAttribute() { |
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.
It's a little unfortunate to have this implemented twice, once on members and once on statements, but it might be worse to lift it up to arbitrary AST nodes, so perhaps it's reasonable to keep it this way.
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.
Yeah, until we have mix-ins :-)
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.
Actually with extensions we have mixins. Let me refactor it.
@@ -3252,6 +3252,14 @@ public XConstraint_EquatableArg(IToken tok, Type a, Type b, bool allowSuperSub, | |||
currentClass = cl; | |||
foreach (MemberDecl member in cl.Members) { | |||
Contract.Assert(VisibleInScope(member)); | |||
if (Attributes.Find(member.Attributes, "only") is UserSuppliedAttributes attribute) { |
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 could use HasOnlyAttribute
.
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.
Implemented.
d => d is TopLevelDeclWithMembers memberContainer && | ||
memberContainer.Members.Any( | ||
member => | ||
Attributes.Contains(member.Attributes, "only") |
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.
Could use HasOnlyAttribute
.
@@ -76,4 +76,8 @@ | |||
|
|||
### Member `AssertOnly` | |||
|
|||
* Assertion has explicit temporary `{:only}` attribute. Must remove the `{:only}` attribute | |||
* Assertion has explicit temporary `{:only}` attribute. Must remove the `{:only}` attribute. |
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.
* Assertion has explicit temporary `{:only}` attribute. Must remove the `{:only}` attribute. | |
* Assertion has explicit temporary `{:only}` attribute. MUST remove the `{:only}` attribute. |
|
||
### Member `MethodOnly` | ||
|
||
* Member has explicit temporary `{:only}` attribute. Must remove the `{:only}` attribute. |
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.
* Member has explicit temporary `{:only}` attribute. Must remove the `{:only}` attribute. | |
* Member has explicit temporary `{:only}` attribute. MUST remove the `{:only}` attribute. |
docs/dev/news/4074.feat
Outdated
@@ -0,0 +1 @@ | |||
`{:only}` attribute for members |
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.
`{:only}` attribute for members | |
Allow the `{:only}` attribute to be used on members in addition to `assert` statements |
…com/dafny-lang/dafny into fix-4074-only-on-single-declaration
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.
It looks like the merge with |
…com/dafny-lang/dafny into fix-4074-only-on-single-declaration
# Conflicts: # Source/DafnyCore/AST/MemberDecls.cs # Source/DafnyCore/Resolver/ResolutionErrors.cs
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.
Looks good!
This PR implements a feature that fixes #4074
I added the corresponding tests, auditor entries and documentations with appropriate links.
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.