Skip to content

Commit 5473500

Browse files
Fix nullref in ComponentsAnalyzer (#18608)
1 parent 2481862 commit 5473500

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Directory.Build.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
-->
3131
<IsStableBuild>false</IsStableBuild>
3232
<IsStableBuild Condition=" '$(DotNetFinalVersionKind)' == 'release' ">true</IsStableBuild>
33+
34+
<!-- Workaround issue with ComponentsAnalyzer throwing for interfaces -->
35+
<DisableImplicitComponentsAnalyzers>true</DisableImplicitComponentsAnalyzers>
3336
</PropertyGroup>
3437

3538
<Import Project="eng\FlakyTests.BeforeArcade.props" />

src/Components/Analyzers/src/InternalUsageAnalyzer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void AnalyzeSymbol(SymbolAnalysisContext context)
126126
// Similar logic here to VisitDeclarationSymbol, keep these in sync.
127127
private void VisitOperationSymbol(OperationAnalysisContext context, ISymbol symbol)
128128
{
129-
if (symbol.ContainingAssembly == context.Compilation.Assembly)
129+
if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly)
130130
{
131131
// The type is being referenced within the same assembly. This is valid use of an "internal" type
132132
return;
@@ -155,7 +155,7 @@ private void VisitOperationSymbol(OperationAnalysisContext context, ISymbol symb
155155
// Similar logic here to VisitOperationSymbol, keep these in sync.
156156
private void VisitDeclarationSymbol(SymbolAnalysisContext context, ISymbol symbol, ISymbol symbolForDiagnostic)
157157
{
158-
if (symbol.ContainingAssembly == context.Compilation.Assembly)
158+
if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly)
159159
{
160160
// This is part of the compilation, avoid this analyzer when building from source.
161161
return;

src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnosticsAnalyzerTest/UsesRendererTypesInDeclarations.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ protected override void HandleException(Exception exception)
2222
throw new NotImplementedException();
2323
}
2424

25-
/*MMParameter*/protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
25+
/*MMParameter*/protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
2626
{
2727
throw new NotImplementedException();
2828
}
2929

3030
/*MMReturnType*/private Renderer GetRenderer() => _field;
31+
32+
public interface ITestInterface
33+
{
34+
}
3135
}
3236
}

0 commit comments

Comments
 (0)