From 547350002a1e5d9d705602bbba0158a72996bad9 Mon Sep 17 00:00:00 2001 From: Brennan Date: Mon, 27 Jan 2020 18:10:19 -0800 Subject: [PATCH] Fix nullref in ComponentsAnalyzer (#18608) --- Directory.Build.props | 3 +++ src/Components/Analyzers/src/InternalUsageAnalyzer.cs | 4 ++-- .../UsesRendererTypesInDeclarations.cs | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 6cbe46561b..b68fd8cb66 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -30,6 +30,9 @@ --> false true + + + true diff --git a/src/Components/Analyzers/src/InternalUsageAnalyzer.cs b/src/Components/Analyzers/src/InternalUsageAnalyzer.cs index 495e4c90fa..af77a42ecc 100644 --- a/src/Components/Analyzers/src/InternalUsageAnalyzer.cs +++ b/src/Components/Analyzers/src/InternalUsageAnalyzer.cs @@ -126,7 +126,7 @@ namespace Microsoft.Extensions.Internal // Similar logic here to VisitDeclarationSymbol, keep these in sync. private void VisitOperationSymbol(OperationAnalysisContext context, ISymbol symbol) { - if (symbol.ContainingAssembly == context.Compilation.Assembly) + if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly) { // The type is being referenced within the same assembly. This is valid use of an "internal" type return; @@ -155,7 +155,7 @@ namespace Microsoft.Extensions.Internal // Similar logic here to VisitOperationSymbol, keep these in sync. private void VisitDeclarationSymbol(SymbolAnalysisContext context, ISymbol symbol, ISymbol symbolForDiagnostic) { - if (symbol.ContainingAssembly == context.Compilation.Assembly) + if (symbol == null || symbol.ContainingAssembly == context.Compilation.Assembly) { // This is part of the compilation, avoid this analyzer when building from source. return; diff --git a/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnosticsAnalyzerTest/UsesRendererTypesInDeclarations.cs b/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnosticsAnalyzerTest/UsesRendererTypesInDeclarations.cs index e2877b0df5..0a0bd11b7b 100644 --- a/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnosticsAnalyzerTest/UsesRendererTypesInDeclarations.cs +++ b/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnosticsAnalyzerTest/UsesRendererTypesInDeclarations.cs @@ -22,11 +22,15 @@ namespace Microsoft.AspNetCore.Components.Analyzers.Tests.TestFiles.ComponentInt throw new NotImplementedException(); } - /*MMParameter*/protected override Task UpdateDisplayAsync(in RenderBatch renderBatch) + /*MMParameter*/protected override Task UpdateDisplayAsync(in RenderBatch renderBatch) { throw new NotImplementedException(); } /*MMReturnType*/private Renderer GetRenderer() => _field; + + public interface ITestInterface + { + } } }