Skip to content

Assertion failed in Microsoft.CodeAnalysis.CSharp.SynthesizedClosureEnvironment.AssertIsClosureScopeSyntax #76559

Open
@tmat

Description

@tmat

Clone https://github.com/microsoft/Microsoft.Unity.Analyzers, open src\Microsoft.Unity.Analyzers.sln in VS with debug build of Roslyn from main branch. Build the solution.

The build also fails with error MSB6006: "csc.exe" exited with code -2146232797

---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
Unexpected value 'VariableDeclarator' of type 'Microsoft.CodeAnalysis.CSharp.SyntaxKind'

   at Roslyn.Utilities.ExceptionUtilities.UnexpectedValue(Object o) in C:\R0\src\Compilers\Core\Portable\InternalUtilities\ExceptionUtilities.cs:line 22

   at Microsoft.CodeAnalysis.CSharp.SynthesizedClosureEnvironment.AssertIsClosureScopeSyntax(SyntaxNode syntaxOpt) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\SynthesizedClosureEnvironment.cs:line 106

   at Microsoft.CodeAnalysis.CSharp.SynthesizedClosureEnvironment..ctor(MethodSymbol topLevelMethod, MethodSymbol containingMethod, Boolean isStruct, SyntaxNode scopeSyntaxOpt, DebugId methodId, DebugId closureId, Nullable`1 rudeEdit) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\SynthesizedClosureEnvironment.cs:line 71

   at Microsoft.CodeAnalysis.CSharp.ClosureConversion.<>c__DisplayClass36_0.<SynthesizeClosureEnvironments>g__MakeFrame|1(Scope scope, ClosureEnvironment env) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\ClosureConversion.cs:line 379

   at Microsoft.CodeAnalysis.CSharp.ClosureConversion.<>c__DisplayClass36_0.<SynthesizeClosureEnvironments>b__0(Scope scope) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\ClosureConversion.cs:line 346

   at Microsoft.CodeAnalysis.CSharp.ClosureConversion.Analysis.VisitScopeTree(Scope treeRoot, Action`1 action) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\ClosureConversion.Analysis.Tree.cs:line 262

   at Microsoft.CodeAnalysis.CSharp.ClosureConversion.Analysis.VisitScopeTree(Scope treeRoot, Action`1 action) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\ClosureConversion.Analysis.Tree.cs:line 266

   at Microsoft.CodeAnalysis.CSharp.ClosureConversion.SynthesizeClosureEnvironments(ArrayBuilder`1 closureDebugInfo) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\ClosureConversion.cs:line 340

   at Microsoft.CodeAnalysis.CSharp.ClosureConversion.Rewrite(BoundStatement loweredBody, NamedTypeSymbol thisType, ParameterSymbol thisParameter, MethodSymbol method, Int32 methodOrdinal, MethodSymbol substitutedSourceMethod, ArrayBuilder`1 lambdaDebugInfoBuilder, ArrayBuilder`1 lambdaRuntimeRudeEditsBuilder, ArrayBuilder`1 closureDebugInfoBuilder, VariableSlotAllocator slotAllocator, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, HashSet`1 assignLocals) in C:\R0\src\Compilers\CSharp\Portable\Lowering\ClosureConversion\ClosureConversion.cs:line 269

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.LowerBodyOrInitializer(MethodSymbol method, Int32 methodOrdinal, BoundStatement body, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState, MethodInstrumentation instrumentation, DebugDocumentProvider debugDocumentProvider, ImmutableArray`1& codeCoverageSpans, BindingDiagnosticBag diagnostics, VariableSlotAllocator& lazyVariableSlotAllocator, ArrayBuilder`1 lambdaDebugInfoBuilder, ArrayBuilder`1 lambdaRuntimeRudeEditsBuilder, ArrayBuilder`1 closureDebugInfoBuilder, ArrayBuilder`1 stateMachineStateDebugInfoBuilder, StateMachineTypeSymbol& stateMachineTypeOpt) in C:\R0\src\Compilers\CSharp\Portable\Compiler\MethodCompiler.cs:line 1437

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) in C:\R0\src\Compilers\CSharp\Portable\Compiler\MethodCompiler.cs:line 1176

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) in C:\R0\src\Compilers\CSharp\Portable\Compiler\MethodCompiler.cs:line 537

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0() in C:\R0\src\Compilers\CSharp\Portable\Compiler\MethodCompiler.cs:line 439

   at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() in C:\R0\src\Compilers\Core\Portable\InternalUtilities\UICultureUtilities.cs:line 139

   at System.Threading.Tasks.Task.Execute()

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)

   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)

   at System.Threading.ThreadPoolWorkQueue.Dispatch()


---------------------------
Abort   Retry   Ignore   
---------------------------

The assertion is triggered when compiling lambda:

Func<CancellationToken, Task<Document>>? action = node switch
{
  BinaryExpressionSyntax bes => ct => ReplaceBinaryExpressionAsync(context.Document, bes, ct),
  InvocationExpressionSyntax ies => ct => ReplaceInvocationExpressionAsync(context.Document, ies, ct),
  _ => null
};

The bound block of the Analysis.Scope is associated with VariableDeclaratorSyntax, which is not an expected closure syntax node.

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions