Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Assertion error ConversionsBase.ClassifyImplicitExtensionMethodThisArgConversion #73342

Open
bernd5 opened this issue May 5, 2024 · 0 comments

Comments

@bernd5
Copy link
Contributor

bernd5 commented May 5, 2024

Version Used: current

Steps to Reproduce:

Create and execute a Test method like:

 [Fact]
 public void TestDebugAssert()
 {
     var code = """
     using System;

     var buffer = new Buffer<int>().Fill(5).Fill(3);

     [System.Runtime.CompilerServices.InlineArray(10)]
     public struct Buffer<T>
     {
         private T _element0;
     }

     public static class BufferExtension
     {
         public static Buffer<T> Fill<T>(this Buffer<T> buf, T i)
         {
             int k = 0;
             foreach (var _ in buf)
             {
                 buf[k++] = i;
             }
             return buf;
         }
     }
     """;
     var comp = CreateCompilation(new[] { code, }, parseOptions: TestOptions.Regular12, targetFramework: TargetFramework.Net80);
     CompileAndVerify(comp);
}

Expected Behavior:

No error

Actual Behavior:

System.InvalidOperationException : Assertion failed

  Stapelüberwachung: 
ThrowingTraceListener.Fail(String message, String detailMessage) Zeile 26
TraceInternal.Fail(String message, String detailMessage)
Debug.Fail(String message, String detailMessage)
ConversionsBase.ClassifyImplicitExtensionMethodThisArgConversion(BoundExpression sourceExpressionOpt, TypeSymbol sourceType, TypeSymbol destination, CompoundUseSiteInfo`1& useSiteInfo) Zeile 1900
NullableWalker.GenerateConversion(Conversions conversions, BoundExpression sourceExpression, TypeSymbol sourceType, TypeSymbol destinationType, Boolean fromExplicitCast, Boolean extensionMethodThisArgument, Boolean isChecked) Zeile 7967
NullableWalker.VisitConversion(BoundConversion conversionOpt, BoundExpression conversionOperand, Conversion conversion, TypeWithAnnotations targetTypeWithNullability, TypeWithState operandType, Boolean checkConversion, Boolean fromExplicitCast, Boolean useLegacyWarnings, AssignmentKind assignmentKind, ParameterSymbol parameterOpt, Boolean reportTopLevelWarnings, Boolean reportRemainingWarnings, Boolean extensionMethodThisArgument, Optional`1 stateForLambda, Boolean trackMembers, Location diagnosticLocation, ArrayBuilder`1 previousArgumentConversionResults) Zeile 8849
NullableWalker.VisitArgumentConversionAndInboundAssignmentsAndPreConditions(BoundConversion conversionOpt, BoundExpression argumentNoConversion, Conversion conversion, RefKind refKind, ParameterSymbol parameter, TypeWithAnnotations parameterType, FlowAnalysisAnnotations parameterAnnotations, VisitResult result, ArrayBuilder`1 conversionResultsBuilder, Boolean extensionMethodThisArgument) Zeile 7247
NullableWalker.<VisitArguments>g__visitArguments|238_1(BoundNode node, ImmutableArray`1 arguments, ImmutableArray`1 argumentsNoConversions, ImmutableArray`1 conversions, ImmutableArray`1 results, ImmutableArray`1 refKindsOpt, ImmutableArray`1 parametersOpt, ImmutableArray`1 argsToParamsOpt, BitVector defaultArguments, Boolean expanded, Boolean invokedAsExtensionMethod, MethodSymbol method, Boolean delayCompletionForTargetMember) Zeile 6813
NullableWalker.VisitArguments(BoundNode node, ImmutableArray`1 arguments, ImmutableArray`1 refKindsOpt, ImmutableArray`1 parametersOpt, ImmutableArray`1 argsToParamsOpt, BitVector defaultArguments, Boolean expanded, Boolean invokedAsExtensionMethod, MethodSymbol method, Boolean delayCompletionForTargetMember, Nullable`1 firstArgumentResult) Zeile 6718
NullableWalker.VisitArguments(BoundNode node, ImmutableArray`1 arguments, ImmutableArray`1 refKindsOpt, ImmutableArray`1 parametersOpt, ImmutableArray`1 argsToParamsOpt, BitVector defaultArguments, Boolean expanded, Boolean invokedAsExtensionMethod, MethodSymbol method, Nullable`1 firstArgumentResult) Zeile 6677
NullableWalker.<VisitCall>g__reinferMethodAndVisitArguments|219_2(BoundCall node, TypeWithState receiverType, Nullable`1 firstArgumentResult) Zeile 6201
NullableWalker.VisitCall(BoundCall node) Zeile 6113
BoundCall.Accept(BoundTreeVisitor visitor) Zeile 6152
BoundTreeVisitor.Visit(BoundNode node) Zeile 151
AbstractFlowPass`2.VisitExpressionWithoutStackGuard(BoundExpression node) Zeile 376
NullableWalker.VisitExpressionWithoutStackGuard(BoundExpression node) Zeile 3463
BoundTreeVisitor.VisitExpressionWithStackGuard(BoundExpression node) Zeile 242
BoundTreeVisitor.VisitExpressionWithStackGuard(Int32& recursionDepth, BoundExpression node) Zeile 216
AbstractFlowPass`2.VisitWithStackGuard(BoundNode node) Zeile 367
AbstractFlowPass`2.VisitAlways(BoundNode node) Zeile 354
AbstractFlowPass`2.Visit(BoundNode node) Zeile 343
NullableWalker.Visit(BoundNode node, Boolean expressionIsRead) Zeile 3579
NullableWalker.Visit(BoundNode node) Zeile 3548
NullableWalker.VisitRvalue(BoundExpression node, Boolean isKnownToBeAnLvalue) Zeile 2161
NullableWalker.VisitRvalueWithState(BoundExpression node) Zeile 2181
NullableWalker.VisitOptionalImplicitConversion(BoundExpression expr, TypeWithAnnotations targetTypeOpt, Boolean useLegacyWarnings, Boolean trackMembers, AssignmentKind assignmentKind) Zeile 8181
NullableWalker.VisitLocalDeclaration(BoundLocalDeclaration node) Zeile 3434
BoundLocalDeclaration.Accept(BoundTreeVisitor visitor) Zeile 3390
BoundTreeVisitor.Visit(BoundNode node) Zeile 151
AbstractFlowPass`2.VisitWithStackGuard(BoundNode node) Zeile 370
AbstractFlowPass`2.VisitAlways(BoundNode node) Zeile 354
AbstractFlowPass`2.Visit(BoundNode node) Zeile 343
NullableWalker.Visit(BoundNode node, Boolean expressionIsRead) Zeile 3579
NullableWalker.Visit(BoundNode node) Zeile 3548
AbstractFlowPass`2.VisitStatement(BoundStatement statement) Zeile 673
NullableWalker.VisitStatement(BoundStatement statement) Zeile 3588
NullableWalker.VisitStatementsWithLocalFunctions(BoundBlock block) Zeile 3111
NullableWalker.VisitBlock(BoundBlock node) Zeile 3014
BoundBlock.Accept(BoundTreeVisitor visitor) Zeile 3294
BoundTreeVisitor.Visit(BoundNode node) Zeile 151
AbstractFlowPass`2.VisitWithStackGuard(BoundNode node) Zeile 370
AbstractFlowPass`2.VisitAlways(BoundNode node) Zeile 354
AbstractFlowPass`2.Visit(BoundNode node) Zeile 343
NullableWalker.Visit(BoundNode node, Boolean expressionIsRead) Zeile 3579
NullableWalker.Visit(BoundNode node) Zeile 3548
AbstractFlowPass`2.VisitMethodBodies(BoundBlock blockBody, BoundBlock expressionBody) Zeile 3716
AbstractFlowPass`2.VisitNonConstructorMethodBody(BoundNonConstructorMethodBody node) Zeile 3609
BoundNonConstructorMethodBody.Accept(BoundTreeVisitor visitor) Zeile 8678
BoundTreeVisitor.Visit(BoundNode node) Zeile 151
AbstractFlowPass`2.VisitWithStackGuard(BoundNode node) Zeile 370
AbstractFlowPass`2.VisitAlways(BoundNode node) Zeile 354
AbstractFlowPass`2.Visit(BoundNode node) Zeile 343
NullableWalker.Visit(BoundNode node, Boolean expressionIsRead) Zeile 3579
NullableWalker.Visit(BoundNode node) Zeile 3548
AbstractFlowPass`2.Scan(Boolean& badRegion) Zeile 425
NullableWalker.Scan(Boolean& badRegion) Zeile 600
AbstractFlowPass`2.Analyze(Boolean& badRegion, Optional`1 initialState) Zeile 448
NullableWalker.Analyze(NullableWalker walker, Symbol symbol, DiagnosticBag diagnostics, Optional`1 initialState, Builder snapshotBuilderOpt, Boolean requiresAnalysis) Zeile 1776
NullableWalker.Analyze(CSharpCompilation compilation, Symbol symbol, BoundNode node, Binder binder, Conversions conversions, DiagnosticBag diagnostics, Boolean useConstructorExitWarnings, Boolean useDelegateInvokeParameterTypes, Boolean useDelegateInvokeReturnType, MethodSymbol delegateInvokeMethodOpt, VariableState initialState, MethodSymbol baseOrThisInitializer, Builder analyzedNullabilityMapOpt, Builder snapshotBuilderOpt, ArrayBuilder`1 returnTypesOpt, Boolean getFinalNullableState, VariableState& finalNullableState, Boolean requiresAnalysis) Zeile 1744
NullableWalker.Analyze(CSharpCompilation compilation, MethodSymbol method, BoundNode node, DiagnosticBag diagnostics, Boolean useConstructorExitWarnings, VariableState initialNullableState, Boolean getFinalNullableState, MethodSymbol baseOrThisInitializer, VariableState& finalNullableState, Boolean requiresAnalysis) Zeile 1371
NullableWalker.AnalyzeIfNeeded(CSharpCompilation compilation, MethodSymbol method, BoundNode node, DiagnosticBag diagnostics, Boolean useConstructorExitWarnings, VariableState initialNullableState, Boolean getFinalNullableState, MethodSymbol baseOrThisInitializer, VariableState& finalNullableState) Zeile 1340
MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, Boolean includeInitializersInBody, BoundNode initializersBody, Boolean reportNullableDiagnostics, ImportChain& importChain, Boolean& originalBodyNested, Boolean& prependedDefaultValueTypeConstructorInitializer, InitialState& forSemanticModel) Zeile 1863
MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) Zeile 1021
MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) Zeile 530
<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0() Zeile 432
<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() Zeile 139

Additional Info

The object identity is not the same - but they represent the same generic instantiation:

 // Spec 7.6.5.2: "An extension method ... is eligible if ... [an] implicit identity, reference,
 // or boxing conversion exists from expr to the type of the first parameter"
 public Conversion ClassifyImplicitExtensionMethodThisArgConversion(BoundExpression sourceExpressionOpt, TypeSymbol sourceType, TypeSymbol destination, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
 {
     Debug.Assert(sourceExpressionOpt is null || Compilation is not null);
     Debug.Assert(sourceExpressionOpt == null || (object)sourceExpressionOpt.Type == sourceType);
     Debug.Assert((object)destination != null);
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 5, 2024
@jaredpar jaredpar added Bug New Feature - Inline Arrays and removed untriaged Issues and PRs which have not yet been triaged by a lead labels May 20, 2024
@jaredpar jaredpar added this to the 17.11 milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants