Skip to content
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

.ApiDesignGuidelines.BasicOverrideEqualsOnOverloadingOperatorEqualsAnalyzer throws NRE in Roslyn.sln #6778

Closed
tmat opened this issue Jul 17, 2023 · 2 comments · Fixed by #6782
Assignees
Labels
Bug The product is not behaving according to its current intended design Reliability Indicates a reliability issue (crash/data loss/test flakiness)
Milestone

Comments

@tmat
Copy link
Member

tmat commented Jul 17, 2023

Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	AD0001	Analyzer 'Microsoft.CodeQuality.VisualBasic.Analyzers.ApiDesignGuidelines.BasicOverrideEqualsOnOverloadingOperatorEqualsAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: Roslyn.Compilers.VisualBasic.IOperation.UnitTests
ISymbol: ExpectedSymbolVerifier (NamedType)

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeQuality.VisualBasic.Analyzers.ApiDesignGuidelines.BasicOverrideEqualsOnOverloadingOperatorEqualsAnalyzer.HasEqualityOperator(INamedTypeSymbol type)
   at Microsoft.CodeQuality.VisualBasic.Analyzers.ApiDesignGuidelines.BasicOverrideEqualsOnOverloadingOperatorEqualsAnalyzer._Closure$__._Lambda$__7-0(SymbolAnalysisContext symbolContext)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
-----
'.	Roslyn.Compilers.VisualBasic.IOperation.UnitTests (net472)	D:\R3\src\Compilers\VisualBasic\Test\IOperation\Roslyn.Compilers.VisualBasic.IOperation.UnitTests.vbproj	1	
@mavasani
Copy link
Contributor

Interesting.. the method has following implementation:

Private Shared Function HasEqualityOperator(type As INamedTypeSymbol) As Boolean
For Each member In type.GetMembers()
Dim method = TryCast(member, IMethodSymbol)
If method?.MethodKind = MethodKind.UserDefinedOperator AndAlso
CaseInsensitiveComparison.Equals(method.Name, WellKnownMemberNames.EqualityOperatorName) Then
Return True
End If
Next
Return False
End Function

Does ?. operator in VB not work the way I think it should?

@mavasani mavasani added Bug The product is not behaving according to its current intended design Area-Microsoft.CodeQuality.Analyzers help wanted The issue is up-for-grabs, and can be claimed by commenting Reliability Indicates a reliability issue (crash/data loss/test flakiness) labels Jul 20, 2023
@mavasani mavasani added this to the .NET vNext milestone Jul 20, 2023
@mavasani
Copy link
Contributor

mavasani commented Jul 20, 2023

Verified with a simple console app that the below can indeed throw an NRE in VB as the second part of the condition gets executed even when method is null:

   If method?.MethodKind = MethodKind.UserDefinedOperator AndAlso 
             CaseInsensitiveComparison.Equals(method.Name, WellKnownMemberNames.EqualityOperatorName) Then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The product is not behaving according to its current intended design Reliability Indicates a reliability issue (crash/data loss/test flakiness)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants