-
Notifications
You must be signed in to change notification settings - Fork 226
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
Fix S3655 FN: VB implicit conversions #6991
Merged
Merged
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,9 +509,10 @@ Class Assignments | |
nullable = Nothing | ||
Dim y As Integer = nullable ' Noncompliant | ||
End Sub | ||
Sub Assignment2() | ||
Dim nullable As Integer? = Nothing | ||
Dim x As Integer = nullable ' FN | ||
Sub Assignment2(nullable As Integer?) | ||
If nullable Is Nothing Then | ||
Dim x As Integer = nullable ' Noncompliant | ||
End If | ||
End Sub | ||
End Class | ||
|
||
|
@@ -574,6 +575,33 @@ Class Casts | |
Sub CTypeDynamicWithNonNullLiteral(i As Integer?) | ||
Dim x = (CTypeDynamic(Of Integer?)(42)).Value | ||
End Sub | ||
|
||
Function ReturnStatement(nullable As Integer?) As Integer | ||
If nullable Is Nothing Then | ||
Return nullable ' Noncompliant | ||
End If | ||
End Function | ||
|
||
Function ReturnAssignment(nullable As Integer?) As Integer | ||
If nullable Is Nothing Then | ||
ReturnAssignment = nullable ' Noncompliant | ||
End If | ||
End Function | ||
|
||
Sub Method(nullable As Integer?) | ||
If nullable Is Nothing Then | ||
Method2(nullable) ' Noncompliant | ||
End If | ||
End Sub | ||
|
||
Sub Method2(i As Integer) | ||
End Sub | ||
|
||
Sub IfExpression(nullable As Integer?) | ||
If nullable Is Nothing Then | ||
Dim x As Integer = If(True, nullable, nullable) ' Noncompliant | ||
End If | ||
End Sub | ||
End Class | ||
|
||
Class WithAliases | ||
|
@@ -584,6 +612,26 @@ Class WithAliases | |
End Sub | ||
End Class | ||
|
||
Class EqualsOperator | ||
Sub EqualsNothing(nullable As Integer?) | ||
If nullable = Nothing Then ' Always evaluates to Nothing (=> false) due to null propagation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would repeat this unusual comment in the testcases below as well. |
||
Dim x As Integer = nullable ' Noncompliant FP, nullable was not actually checked for null | ||
End If | ||
End Sub | ||
|
||
Sub UnequalsNothing(nullable As Integer?) | ||
If nullable <> Nothing Then ' Always evaluates to Nothing (=> false) due to null propagation | ||
Dim x As Integer = nullable ' Compliant | ||
End If | ||
End Sub | ||
|
||
Sub UqualsOrUnequals(nullable As Integer?) | ||
If (nullable <> Nothing) OrElse (nullable = Nothing) Then | ||
Dim x As Integer = nullable ' Noncompliant FP | ||
End If | ||
End Sub | ||
End Class | ||
|
||
Namespace TypeWithValueProperty | ||
Class TypeWithValueProperty | ||
Private Sub Basics1() | ||
|
@@ -597,7 +645,7 @@ Namespace TypeWithValueProperty | |
End Sub | ||
|
||
Private Sub ImplicitCast() | ||
Dim i As StructWithValuePropertyAndCastOperators = CTypeDynamic(Of Integer?)(Nothing) | ||
Dim i As StructWithValuePropertyAndCastOperators = Nothing | ||
Dim x = i.Value | ||
End Sub | ||
|
||
|
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.
I would add a test with
<> Nothing
(which has a behavior very similar to= Nothing
:And also the following case, which shows how
=
and<>
break tautology w.r.t.OrElse
:Of course you could "exploit" the fact that
=
and<>
liftNothing
to get all sort of ternary logic behaviors. I would let you decide how deep you think it's worth exploring this path.