dotnet / dotnet/roslyn

Crash in compiler during async rewrite of an assignment to an indexer of a type parameter when InterpolatedStringHandler is involved

Open
#79,416 1 comment 0 reactions 1 assignee Claimed by @333fred View on GitHub
Area-Compilers
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

```
using System.Threading.Tasks;

[System.Runtime.CompilerServices.InterpolatedStringHandler]
struct InterpolationHandler
{

public InterpolationHandler(int literalLength, int formattedCount, TR x)
{
}
public void AppendLiteral(string value) { }
public void AppendFormatted(T hole, int alignment = 0, string format = null) => throw null;
}

interface I1
{
int this[int i, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgument("")] InterpolationHandler h] {get; set;}
}

struct S1 : I1
{
public int this[int i, [System.Runtime.CompilerServices.InterpolatedStringHandlerArgument("")] InterpolationHandler h]
{
get
{
return 0;
}
set {}
}
}

class Program
{
static async Task Test3(T x) where T : I1
{
x[Get1(), $""] = await Get1Async();
}

static int Get1()
{
return 1;
}

static async Task Get1Async()
{
await Task.Yield();
return 1;
}
}
```

Observed:
```
System.InvalidOperationException: Unexpected value 'ComplexConditionalReceiver' of type 'Microsoft.CodeAnalysis.CSharp.BoundKind'
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.HoistExpression(BoundExpression expr, SyntaxNode awaitSyntaxOpt, Int32 syntaxOffset, RefKind refKind, ArrayBuilder`1 sideEffects, ArrayBuilder`1 hoistedFields, Boolean& needsSacrificialEvaluation)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.HoistRefInitialization(LocalSymbol local, BoundAssignmentOperator node)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.VisitAssignmentOperator(BoundAssignmentOperator node)
at Microsoft.CodeAnalysis.CSharp.BoundAssignmentOperator.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriterWithStackGuard.VisitExpressionOrPatternWithoutStackGuard(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionOrPatternWithStackGuard(Int32& recursionDepth, BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriterWithStackGuard.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.AsyncMethodToStateMachineRewriter.VisitExpressionStatement(BoundExpressionStatement node)
at Microsoft.CodeAnalysis.CSharp.BoundExpressionStatement.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriterWithStackGuard.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[BoundStatement](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitList[BoundStatement](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeToDifferentEnclosingContextRewriter.VisitBlock(BoundBlock node, Boolean removeInstrumentation)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.<>c__DisplayClass48_0.b__0()
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.PossibleIteratorScope(ImmutableArray`1 locals, Func`1 wrapped)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.BoundBlock.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriterWithStackGuard.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitSequencePoint(BoundSequencePoint node)
at Microsoft.CodeAnalysis.CSharp.BoundSequencePoint.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriterWithStackGuard.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.DoVisitList[BoundStatement](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriter.VisitList[BoundStatement](ImmutableArray`1 list)
at Microsoft.CodeAnalysis.CSharp.BoundTreeToDifferentEnclosingContextRewriter.VisitBlock(BoundBlock node, Boolean removeInstrumentation)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.<>c__DisplayClass48_0.b__0()
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.PossibleIteratorScope(ImmutableArray`1 locals, Func`1 wrapped)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.VisitBlock(BoundBlock node)
at Microsoft.CodeAnalysis.CSharp.BoundBlock.Accept(BoundTreeVisitor visitor)
at Microsoft.CodeAnalysis.CSharp.BoundTreeRewriterWithStackGuard.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.MethodToStateMachineRewriter.Visit(BoundNode node)
at Microsoft.CodeAnalysis.CSharp.AsyncMethodToStateMachineRewriter.VisitBody(BoundStatement body)
at Microsoft.CodeAnalysis.CSharp.AsyncMethodToStateMachineRewriter.GenerateMoveNext(BoundStatement body, MethodSymbol moveNextMethod)
at Microsoft.CodeAnalysis.CSharp.AsyncRewriter.GenerateMoveNext(SynthesizedImplementationMethod moveNextMethod)
at Microsoft.CodeAnalysis.CSharp.AsyncRewriter.GenerateMethodImplementations()
at Microsoft.CodeAnalysis.CSharp.StateMachineRewriter.Rewrite()
at Microsoft.CodeAnalysis.CSharp.AsyncRewriter.Rewrite(BoundStatement bodyWithAwaitLifted, MethodSymbol method, Int32 methodOrdinal, ArrayBuilder`1 stateMachineStateDebugInfoBuilder, VariableSlotAllocator slotAllocatorOpt, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, AsyncStateMachine& stateMachineType)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.LowerBodyOrInitializer(MethodSymbol method, SourceExtensionImplementationMethodSymbol extensionImplementationMethod, 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)
at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.