-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
4 - In ReviewA fix for the issue is submitted for review.A fix for the issue is submitted for review.Area-CompilersBug
Milestone
Description
[Fact]
[WorkItem(16825, "https://github.com/dotnet/roslyn/issues/16825")]
public void NullCoalescingOperatorWithTupleNames()
{
// See section 7.13 of the spec, regarding the null-coalescing operator
var source = @"
public class C
{
public void M()
{
(int a, int b)? nab = (1, 2);
(int a, int c)? nac = (1, 3);
var x1 = nab ?? nac; // (a, b)?
var x2 = nab ?? nac.Value; // (a, b)
var x3 = new C() ?? nac; // C
var x4 = new D() ?? nac; // (a, c)?
var x5 = nab != null ? nab : nac; // (a, )?
var x6 = nab ?? (a: 1, c: 3); // (a, b)
var x7 = nab ?? (a: 1, c: 3); // (a, b)
var x8 = new C() ?? (a: 1, c: 3); // C
var x9 = new D() ?? (a: 1, c: 3); // (a, c)
var x6double = nab ?? (d: 1.1, c: 3); // (a, c)
}
public static implicit operator C((int, int) x) { throw null; }
}
public class D
{
public static implicit operator (int d1, int d2) (D x) { throw null; }
}
";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics(
// (16,32): warning CS8123: The tuple element name 'c' is ignored because a different name is specified by the target type '(int a, int b)'.
// var x6 = nab ?? (a: 1, c: 3); // (a, b)?
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "c: 3").WithArguments("c", "(int a, int b)").WithLocation(16, 32),
// (17,32): warning CS8123: The tuple element name 'c' is ignored because a different name is specified by the target type '(int a, int b)'.
// var x7 = nab ?? (a: 1, c: 3); // (a, b)
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "c: 3").WithArguments("c", "(int a, int b)").WithLocation(17, 32),
// (18,30): warning CS8123: The tuple element name 'a' is ignored because a different name is specified by the target type '(int, int)'.
// var x8 = new C() ?? (a: 1, c: 3); // C
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "a: 1").WithArguments("a", "(int, int)").WithLocation(18, 30),
// (18,36): warning CS8123: The tuple element name 'c' is ignored because a different name is specified by the target type '(int, int)'.
// var x8 = new C() ?? (a: 1, c: 3); // C
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "c: 3").WithArguments("c", "(int, int)").WithLocation(18, 36)
);
_ = comp.GetEmitDiagnostics(); // System.InvalidOperationException : Assertion failed
// ... rest omitted ...
}
Message:
System.InvalidOperationException : Assertion failed
Stack Trace:
ThrowingTraceListener.Fail(String message, String detailMessage) line 26
TraceInternal.Fail(String message, String detailMessage)
TraceProvider.Fail(String message, String detailMessage)
Debug.Fail(String message, String detailMessage)
Debug.Assert(Boolean condition)
LocalRewriter.MakeNullCoalescingOperator(SyntaxNode syntax, BoundExpression rewrittenLeft, BoundExpression rewrittenRight, BoundValuePlaceholder leftPlaceholder, BoundExpression leftConversion, BoundNullCoalescingOperatorResultKind resultKind, TypeSymbol rewrittenResultType) line 157
LocalRewriter.VisitNullCoalescingOperator(BoundNullCoalescingOperator node) line 21
BoundNullCoalescingOperator.Accept(BoundTreeVisitor visitor) line 1980
BoundTreeVisitor.Visit(BoundNode node) line 151
BoundTreeRewriterWithStackGuard.VisitExpressionWithoutStackGuard(BoundExpression node) line 97
BoundTreeVisitor.VisitExpressionWithStackGuard(BoundExpression node) line 242
BoundTreeVisitor.VisitExpressionWithStackGuard(Int32& recursionDepth, BoundExpression node) line 216
BoundTreeRewriterWithStackGuard.VisitExpressionWithStackGuard(BoundExpression node) line 92
LocalRewriter.VisitExpressionImpl(BoundExpression node) line 210
LocalRewriter.VisitExpression(BoundExpression node) line 184
LocalRewriter.VisitLocalDeclaration(BoundLocalDeclaration node) line 16
BoundLocalDeclaration.Accept(BoundTreeVisitor visitor) line 3290
LocalRewriter.VisitStatement(BoundStatement node) line 195
LocalRewriter.VisitPossibleUsingDeclaration(BoundStatement node, ImmutableArray`1 statements, Int32 statementIndex, Boolean& replacedLocalDeclarations) line 101
LocalRewriter.VisitStatementSubList(ArrayBuilder`1 builder, ImmutableArray`1 statements, Int32 startIndex) line 59
LocalRewriter.VisitBlock(BoundBlock node) line 20
BoundBlock.Accept(BoundTreeVisitor visitor) line 3189
LocalRewriter.VisitStatement(BoundStatement node) line 195
LocalRewriter.Rewrite(CSharpCompilation compilation, MethodSymbol method, Int32 methodOrdinal, NamedTypeSymbol containingType, BoundStatement statement, TypeCompilationState compilationState, SynthesizedSubmissionFields previousSubmissionFields, Boolean allowOmissionOfConditionalCalls, Boolean instrumentForDynamicAnalysis, ImmutableArray`1& dynamicAnalysisSpans, DebugDocumentProvider debugDocumentProvider, BindingDiagnosticBag diagnostics, Boolean& sawLambdas, Boolean& sawLocalFunctions, Boolean& sawAwaitInExceptionHandler) line 108
MethodCompiler.LowerBodyOrInitializer(MethodSymbol method, Int32 methodOrdinal, BoundStatement body, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState, Boolean instrumentForDynamicAnalysis, DebugDocumentProvider debugDocumentProvider, ImmutableArray`1& dynamicAnalysisSpans, BindingDiagnosticBag diagnostics, VariableSlotAllocator& lazyVariableSlotAllocator, ArrayBuilder`1 lambdaDebugInfoBuilder, ArrayBuilder`1 closureDebugInfoBuilder, StateMachineTypeSymbol& stateMachineTypeOpt) line 1372
MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) line 1190
MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) line 525
<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0() line 419
<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() line 139
Task.InnerInvoke()
<.cctor>b__272_0(Object obj)
ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
MethodCompiler.WaitForWorkers() line 330
MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean emitTestCoverageData, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) line 165
CSharpCompilation.CompileMethods(CommonPEModuleBuilder moduleBuilder, Boolean emittingPdb, Boolean emitMetadataOnly, Boolean emitTestCoverageData, DiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) line 3227
Compilation.Emit(Stream peStream, Stream metadataPEStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, RebuildData rebuildData, CompilationTestData testData, CancellationToken cancellationToken) line 2837
Compilation.Emit(Stream peStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Stream metadataPEStream, RebuildData rebuildData, CancellationToken cancellationToken) line 2778
Compilation.Emit(Stream peStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Stream metadataPEStream, CancellationToken cancellationToken) line 2666
DiagnosticExtensions.GetEmitDiagnostics[TCompilation](TCompilation c, EmitOptions options, IEnumerable`1 manifestResources) line 351
DiagnosticExtensions.GetEmitDiagnostics[TCompilation](TCompilation c) line 363
CodeGenTupleTests.NullCoalescingOperatorWithTupleNames() line 19278
We hit this assertion:
Debug.Assert(convertedLeft.HasErrors || convertedLeft.Type!.Equals(rewrittenResultType, TypeCompareKind.IgnoreDynamicAndTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes));
Relates to #60052
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
4 - In ReviewA fix for the issue is submitted for review.A fix for the issue is submitted for review.Area-CompilersBug