Skip to content
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

Merged
merged 17 commits into from
Jun 8, 2023

Conversation

MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented May 24, 2023

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.

@MikaelMayer MikaelMayer requested a review from atomb May 24, 2023 16:50
Copy link
Member

@atomb atomb left a 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.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mitigationIETF: "Must remove the [{:only}] attribute.",
mitigationIETF: "MUST remove the [{:only}] attribute.",

@@ -105,6 +106,19 @@ public MemberDecl(RangeToken rangeToken, Name name, bool hasStaticKeyword, bool
}

public virtual IEnumerable<Expression> SubExpressions => Enumerable.Empty<Expression>();

public bool HasOnlyAttribute() {
Copy link
Member

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.

Copy link
Member Author

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 :-)

Copy link
Member Author

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) {
Copy link
Member

Choose a reason for hiding this comment

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

This could use HasOnlyAttribute.

Copy link
Member Author

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")
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Member has explicit temporary `{:only}` attribute. Must remove the `{:only}` attribute.
* Member has explicit temporary `{:only}` attribute. MUST remove the `{:only}` attribute.

@@ -0,0 +1 @@
`{:only}` attribute for members
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`{:only}` attribute for members
Allow the `{:only}` attribute to be used on members in addition to `assert` statements

atomb
atomb previously approved these changes May 24, 2023
Copy link
Member

@atomb atomb left a comment

Choose a reason for hiding this comment

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

:shipit:

@MikaelMayer MikaelMayer enabled auto-merge (squash) May 25, 2023 15:19
@atomb
Copy link
Member

atomb commented May 30, 2023

It looks like the merge with master led to some test failures.

Copy link
Member

@atomb atomb 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!

@MikaelMayer MikaelMayer merged commit 1517136 into master Jun 8, 2023
@MikaelMayer MikaelMayer deleted the fix-4074-only-on-single-declaration branch June 8, 2023 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{:only} should also work on single declarations
2 participants