-
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: Add UT for conversions #6857
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.
The PreProcessCheck seems unnecessary.
...ests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Nullable.cs
Outdated
Show resolved
Hide resolved
...ests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Nullable.cs
Outdated
Show resolved
Hide resolved
...ests/SonarAnalyzer.UnitTest/SymbolicExecution/Roslyn/RoslynSymbolicExecutionTest.Nullable.cs
Show resolved
Hide resolved
aba95af
to
ae95ddf
Compare
96fdc59
to
da9c734
Compare
ae95ddf
to
793e4d8
Compare
da9c734
to
3231c95
Compare
3231c95
to
8cd776a
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.
There is an IsUserDefined
property. I would propose using that to check for user-defined conversions.
@@ -26,7 +26,7 @@ internal sealed class Conversion : SimpleProcessor<IConversionOperationWrapper> | |||
operation.ToConversion(); | |||
|
|||
protected override ProgramState Process(SymbolicContext context, IConversionOperationWrapper conversion) => | |||
context.State[conversion.Operand] is { } value | |||
context.State[conversion.Operand] is { } value && conversion.OperatorMethod is null |
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.
Is this the "is user defined conversion" check? If so, it would be better to check IsUserDefined. It is accessible via the Conversion property.
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 is user defined when the symbol is not null, that's what I've observed when I compared few cases and also here
https://github.com/dotnet/roslyn/blob/aff2a21bbf6726f0ecab4660568e068aa923ef55/src/Compilers/Core/Portable/Operations/CommonConversion.cs#L72-L81
So those two conditions are functionally equivalent. IsUserDefined
is definitely more readable, unfortunately, CommonConversion
is not available in the ShimLayer and would require heavy scaffolding.
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. Can we add a small comment like // is a built-in conversion
?
I do remember that there were some surprises with built-in conversions for decimal as it reported a conversion method back when I worked on the operator intellisense. It might be worth adding test cases for decimal and System.Half. If there is something wrong we can whitelist these symbols in a later PR.
8cd776a
to
8f78c5a
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 System.Half
and decimal
test cases might reveal a surprise.
Tests 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.
LGTM. You may want to add a code comment to conversion.OperatorMethod is null
like // built-in conversions only
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Part of #6812
Add UTs for implicit and explicit conversions to be sure they work as expected.