-
Notifications
You must be signed in to change notification settings - Fork 297
Flag Assert.AreEqual(x, x) / AreSame(x, x) / AreNotEqual(x, x) / AreNotSame(x, x) (#9087)
#9088
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
Open
Evangelink
wants to merge
4
commits into
main
Choose a base branch
from
evangelink/issue-9087-flag-identical-operands
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f0195a9
Flag Assert.AreEqual/AreSame (and AreNotEqual/AreNotSame) with identi…
Evangelink e6f5d0d
Address review: don't unwrap user-defined conversions
Evangelink b220434
Address self-review on #9088: exclude indexers from IsEquivalentRefer…
7ff443b
Address review on #9088: add AreNotSame-with-message and property cov…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[MAJOR] Algorithmic Correctness / Analyzer Quality — false positive on custom indexers
The
IPropertyReferenceOperationarm does not exclude custom indexers (Property.IsIndexer == true). In Roslyn,list[0]on any type that has a C# indexer (List<T>,Dictionary<K,V>,ImmutableArray<T>, any user-definedthis[...]accessor) produces anIPropertyReferenceOperationwhoseProperty.IsIndexer == true. The current code checks only that the property symbol and the receiver instance are equivalent — it does not compare the index arguments.Concrete false-positive scenario:
Both operands produce
IPropertyReferenceOperationwith the sameItemproperty symbol and the samelistlocal as instance. The switch arm returnstrue, causing a spurious diagnostic.Note: plain array access (
arr[i]) producesIArrayElementReferenceOperation, notIPropertyReferenceOperation, so that case is already excluded by the_ => falsedefault. Only C#-defined indexers hit this arm.The
<remarks>doc comment already states the correct intent — "This intentionally excludes method invocations and indexer accesses" — but the code doesn't enforce it forIPropertyReferenceOperation.Recommended fix — add
!pra.Property.IsIndexeras the first guard:A matching no-diagnostic test is also needed, e.g.:
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.
Good catch -- fixed in b220434. Added
!pra.Property.IsIndexeras the first guard on theIPropertyReferenceOperationarm solist[0]/dict[k]/ any user-defined indexer access falls through to_ => false. The xmldoc remark already documented this intent (This intentionally excludes method invocations and indexer accesses); the code now enforces it. AddedWhenAssertAreEqualIsPassedIndexerAccess_NoDiagnosticexercisinglist[0] vs list[1],list[0] vs list[0], and theAreSamevariant. Review reply handled.