Skip to content

Conversation

@333fred
Copy link
Member

@333fred 333fred commented Dec 19, 2025

The existing pattern is 3 nots and an (implicit) and. Can be much simpler as just an or. I found the existing condition highly complex to read.

The existing pattern is 3 `not`s and an (implicit) `and`. Can be much simpler as just an `or`.
@333fred 333fred requested a review from a team as a code owner December 19, 2025 18:06
@333fred
Copy link
Member Author

333fred commented Dec 19, 2025

@dotnet/roslyn-compiler for a simple review

else if (parameter.IsExtensionParameter() &&
(InParameterDefaultValue || InAttributeArgument ||
this.ContainingMember() is not { Kind: not SymbolKind.NamedType, IsStatic: false } || // We are not in an instance member
this.ContainingMember() is { Kind: SymbolKind.NamedType } or { IsStatic: true } || // We are not in an instance member
Copy link
Contributor

@AlekseyTs AlekseyTs Dec 19, 2025

Choose a reason for hiding this comment

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

Strictly speaking this rewrite is not semantically equivalent because the recursive pattern includes an implicit not null test. Therefore, the process of pushing the not down the pattern should result in an explicit null test, combined with or with the rest. It is quite possible that it was intentional to have the implicit not null test to protect the following line from a possible null dereference. I suggest to use semantically equivalent rewrite and to protect the recently added this.ContainingMember().IsStatic access in the body of the if #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, @AlekseyTs please take another look.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 3). Since some other code was changed to make it more robust, please, adjust the title so that it no longer sounds like a pure refactoring change.

@333fred 333fred enabled auto-merge (squash) December 19, 2025 19:36
@333fred
Copy link
Member Author

333fred commented Dec 19, 2025

adjust the title so that it no longer sounds like a pure refactoring change.

The commit message and title will be adjusted, I'll leave the GitHub title itself alone to avoid breaking inboxes.

@333fred 333fred merged commit a97ef5d into dotnet:main Dec 20, 2025
24 of 25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Dec 20, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
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.

4 participants