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

Fix crash and record diagnostic location in preview feature analyzer #5809

Merged
merged 5 commits into from
Jan 27, 2022

Conversation

Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Jan 24, 2022

@jeffhandley Can you take a look?

Fixes #5802

@codecov
Copy link

codecov bot commented Jan 24, 2022

Codecov Report

Merging #5809 (10921b2) into main (f471d33) will increase coverage by 0.00%.
The diff coverage is 90.00%.

@@           Coverage Diff           @@
##             main    #5809   +/-   ##
=======================================
  Coverage   95.58%   95.58%           
=======================================
  Files        1284     1284           
  Lines      296834   296805   -29     
  Branches    18101    18090   -11     
=======================================
- Hits       283725   283714   -11     
+ Misses      10670    10655   -15     
+ Partials     2439     2436    -3     

Copy link
Member

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @Youssef1313 overall LGTM , could you add similar logic into VB code? Looks at least this method could benefit fom using TypeStatementSyntax and TypeBlockSyntax instead

Protected Overrides Function GetPreviewInterfaceNodeForTypeImplementingPreviewInterface(typeSymbol As ISymbol, previewInterfaceSymbol As ISymbol) As SyntaxNode
Dim typeSymbolDeclaringReferences = typeSymbol.DeclaringSyntaxReferences
For Each syntaxReference In typeSymbolDeclaringReferences
Dim typeSymbolDefinition = syntaxReference.GetSyntax()
Dim classStatement = TryCast(typeSymbolDefinition, ClassStatementSyntax)
If classStatement IsNot Nothing Then
Dim classBlock = TryCast(classStatement.Parent, ClassBlockSyntax)
If classBlock IsNot Nothing Then
Dim syntaxNode As SyntaxNode = Nothing
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(classBlock.Inherits, previewInterfaceSymbol, syntaxNode) Then
Return syntaxNode
Else
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(classBlock.Implements, previewInterfaceSymbol, syntaxNode) Then
Return syntaxNode
End If
End If
End If
End If
Dim structStatement = TryCast(typeSymbolDefinition, StructureStatementSyntax)
If structStatement IsNot Nothing Then
Dim structBlock = TryCast(structStatement.Parent, StructureBlockSyntax)
If structBlock IsNot Nothing Then
Dim syntaxNode As SyntaxNode = Nothing
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(structBlock.Inherits, previewInterfaceSymbol, syntaxNode) Then
Return syntaxNode
Else
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(structBlock.Implements, previewInterfaceSymbol, syntaxNode) Then
Return syntaxNode
End If
End If
End If
End If
Dim interfaceStatement = TryCast(typeSymbolDefinition, InterfaceStatementSyntax)
If interfaceStatement IsNot Nothing Then
Dim interfaceBlock = TryCast(interfaceStatement.Parent, InterfaceBlockSyntax)
If interfaceBlock IsNot Nothing Then
Dim syntaxNode As SyntaxNode = Nothing
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(interfaceBlock.Implements, previewInterfaceSymbol, syntaxNode) Then
Return syntaxNode
Else
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(interfaceBlock.Inherits, previewInterfaceSymbol, syntaxNode) Then
Return syntaxNode
End If
End If
End If
End If
Next
Return Nothing
End Function

Copy link
Member

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Youssef1313 looks great. The perf failures unrelated and reported in #5790, merging

@buyaa-n buyaa-n merged commit 824df07 into dotnet:main Jan 27, 2022
@github-actions github-actions bot added this to the vNext milestone Jan 27, 2022
@Youssef1313 Youssef1313 deleted the preview-features-nre branch January 28, 2022 00:58
Evangelink pushed a commit to Evangelink/roslyn-analyzers that referenced this pull request Jan 28, 2022
…otnet#5809)

* Fix crash and record diagnostic location in preview feature analyzer
@jmarolf jmarolf modified the milestones: vNext, .NET 7.x Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSharpDetectPreviewFeatureAnalyzer hitting NullReferenceException when run on Corelib
4 participants