Skip to content

Internal Compiler Error: NullReferenceException / NullableWalker.LocalState.SetValue for switch over bool in lambda #55227

@bernd5

Description

@bernd5

Version Used: 4.0.0-3.21358.10

Steps to Reproduce:
Compile / Paste the following code into the editor (reduced code):

using System;

static class Program
{
    public static void Main()
    {
    }

    public static object Foo(object a)
    {
        var isNullCheck = new global::System.Func<object, object>((p) =>
        {
            switch (p == null)
            {
                case var isnull:
                    return isnull;
            }
        });
        return isNullCheck(a);
    }
}

Expected Behavior:
Compilation without error

Actual Behavior:
Compiler error NullReferenceException

Stacktrace

StreamJsonRpc.RemoteInvocationException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__139`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__17`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
RPC server exception:
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.LocalState.SetValue(Int32 id, Int32 index, NullableFlowState value)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.DeclareLocal(LocalSymbol local)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.DeclareLocals(ImmutableArray`1 locals)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitSwitchStatementDispatch(BoundSwitchStatement node)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitSwitchStatement(BoundSwitchStatement node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitStatementsWithLocalFunctions(BoundBlock block)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitBlock(BoundBlock node)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitWithStackGuard(BoundNode node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.AnalyzeLocalFunctionOrLambda(IBoundLambdaOrFunction lambdaOrFunction, MethodSymbol lambdaOrFunctionSymbol, LocalState state, MethodSymbol delegateInvokeMethod, Boolean useDelegateInvokeParameterTypes, Boolean useDelegateInvokeReturnType)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitLambda(BoundLambda node, NamedTypeSymbol delegateTypeOpt, Optional`1 initialState)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitDelegateCreationExpression(BoundDelegateCreationExpression node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitExpressionWithoutStackGuard(BoundExpression node)
      bei Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionWithStackGuard(BoundExpression node)
      bei Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionWithStackGuard(Int32& recursionDepth, BoundExpression node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitOptionalImplicitConversion(BoundExpression expr, TypeWithAnnotations targetTypeOpt, Boolean useLegacyWarnings, Boolean trackMembers, AssignmentKind assignmentKind)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitLocalDeclaration(BoundLocalDeclaration node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitStatementsWithLocalFunctions(BoundBlock block)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.VisitBlock(BoundBlock node)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitWithStackGuard(BoundNode node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.Visit(BoundNode node)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitMethodBodies(BoundBlock blockBody, BoundBlock expressionBody)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitNonConstructorMethodBody(BoundNonConstructorMethodBody node)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitWithStackGuard(BoundNode node)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.Visit(BoundNode node)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.Scan(Boolean& badRegion)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.Scan(Boolean& badRegion)
      bei Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.Analyze(Boolean& badRegion, Optional`1 initialState)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.Analyze(NullableWalker walker, Symbol symbol, DiagnosticBag diagnostics, Optional`1 initialState, Builder snapshotBuilderOpt, Boolean requiresAnalysis)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.Analyze(CSharpCompilation compilation, Symbol symbol, BoundNode node, Binder binder, Conversions conversions, DiagnosticBag diagnostics, Boolean useConstructorExitWarnings, Boolean useDelegateInvokeParameterTypes, Boolean useDelegateInvokeReturnType, MethodSymbol delegateInvokeMethodOpt, VariableState initialState, Builder analyzedNullabilityMapOpt, Builder snapshotBuilderOpt, ArrayBuilder`1 returnTypesOpt, Boolean getFinalNullableState, VariableState& finalNullableState, Boolean requiresAnalysis)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.AnalyzeWithSemanticInfo(CSharpCompilation compilation, Symbol symbol, BoundNode node, Binder binder, VariableState initialState, DiagnosticBag diagnostics, Boolean createSnapshots, Boolean requiresAnalysis)
      bei Microsoft.CodeAnalysis.CSharp.NullableWalker.AnalyzeAndRewrite(CSharpCompilation compilation, Symbol symbol, BoundNode node, Binder binder, VariableState initialState, DiagnosticBag diagnostics, Boolean createSnapshots, SnapshotManager& snapshotManager, ImmutableDictionary`2& remappedSymbols)
      bei Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, VariableState nullableInitialState, ImportChain& importChain, Boolean& originalBodyNested, InitialState& forSemanticModel)
      bei Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState)
      bei Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
      bei Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass23_0.<CompileNamedTypeAsync>b__0()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
      bei Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0()
      bei System.Threading.Tasks.Task.Execute()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei Microsoft.CodeAnalysis.CSharp.MethodCompiler.WaitForWorkers()
      bei Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean emitTestCoverageData, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
      bei Microsoft.CodeAnalysis.CSharp.CSharpCompilation.<GetDiagnosticsForMethodBodiesInTree>g__compileMethodBodiesAndDocComments|217_0(SyntaxTree filterTree, Nullable`1 filterSpan, BindingDiagnosticBag bindingDiagnostics, CancellationToken cancellationToken)
      bei Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForMethodBodiesInTree(SyntaxTree tree, Nullable`1 span, CancellationToken cancellationToken)
      bei Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForSyntaxTree(CompilationStage stage, SyntaxTree syntaxTree, Nullable`1 filterSpanWithinTree, Boolean includeEarlierStages, CancellationToken cancellationToken)
      bei Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetDiagnostics(Nullable`1 span, CancellationToken cancellationToken)
      bei Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GenerateCompilationEvents(AnalysisScope analysisScope, CancellationToken cancellationToken)
      bei Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.<ComputeAnalyzerDiagnosticsAsync>d__67.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.<ComputeAnalyzerSemanticDiagnosticsAsync>d__66.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.<GetAnalysisResultCoreAsync>d__64.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Diagnostics.Extensions.<GetAnalysisResultAsync>d__12.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Diagnostics.Extensions.<GetAnalysisResultAsync>d__11.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.<AnalyzeAsync>d__9.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.<GetDiagnosticsAsync>d__8.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.<>c__DisplayClass3_0.<<CalculateDiagnosticsAsync>b__0>d.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
      bei Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.<RunServiceImplAsync>d__12`1.MoveNext()
   --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
      bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      bei Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions