-
Notifications
You must be signed in to change notification settings - Fork 231
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
SE - Nullable: Learn object constraint from value comparison #6925
SE - Nullable: Learn object constraint from value comparison #6925
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.
There might be a regression for unknownNullableBool != null
and that test case seems to be missing. Also changed test cases should use HaveOnlyConstraint()
.
analyzers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/OperationProcessors/Binary.cs
Outdated
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Outdated
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Outdated
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Outdated
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Outdated
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Show resolved
Hide resolved
...r.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Branching.LearnConstraint.cs
Show resolved
Hide resolved
e5cbfb9
to
90a8d8b
Compare
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.
A test case with bool? arg
is still missing.
f9d14bd
to
3339b76
Compare
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.
Test coverage is good now. I have one suggestion for the special casing of the nullable bool you may want to give a try.
// We can fall through ?? because "constraint" and "testedSymbol" are exclusive. Symbols with the constraint will be recognized as "constraint" side. | ||
if ((OperandConstraint(binary.LeftOperand) ?? OperandConstraint(binary.RightOperand)) is { } constraint | ||
&& (OperandSymbolWithoutConstraint(binary.LeftOperand) ?? OperandSymbolWithoutConstraint(binary.RightOperand)) is { } testedSymbol) | ||
&& (OperandSymbolWithoutConstraint(binary.LeftOperand) ?? OperandSymbolWithoutConstraint(binary.RightOperand)) is { } testedSymbol | ||
&& !(useOpposite && constraint is BoolConstraint && testedSymbol.GetSymbolType().IsNullableBoolean())) |
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 really ugly special casing. Shouldn't this do the same thing 🤔 ?
&& !(useOpposite && constraint is BoolConstraint && testedSymbol.GetSymbolType().IsNullableBoolean())) | |
&& !(useOpposite && testedSymbol.GetSymbolType().IsNullable())) |
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.
In theory should, until someone adds a BoolConstraint
to something else than bool
somewhere. I'll keep it as we don't have IsNullable
and I don't want to add it for this
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.
D'accord. Can you add a code comment with examples about why we need this special case and also add a hint that ObjectConstraint.ApplyOpposite(true)
does the same logic but at a different place? Our future self will have a hard time understanding what is going on here.
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.
Added
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.
A code comment is justified in this case.
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.
LGTM
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Part of #6812
Rebase will be needed once #6923 is merged