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

Custom modifiers are not copied in array type collection expression lowering #73804

Open
RikkiGibson opened this issue May 31, 2024 · 0 comments

Comments

@RikkiGibson
Copy link
Contributor

RikkiGibson commented May 31, 2024

Add the following test in 'CustomModifierCopyTests'. It appears that lowering is dropping the custom modifier which was present in the type of [] in initial binding.

It's not obvious to me whether this difference represents a real problem or not. Perhaps when the array type is created in the method implementation, and custom modifiers are missing which were present on the return type, then bad things could happen.

        /// <summary>
        /// Test copying custom modifiers in/on property types.
        /// </summary>
        [Fact]
        public void TestPropertyOverrideCombinations_CollectionExpressionConversion()
        {
            var text = @"
class Derived : PropertyCustomModifierCombinations
{
    public override int[] Property11 { get => []; set { } }
    public override int[] Property10 { get => []; set { } }
    public override int[] Property01 { get => []; set { } }
    public override int[] Property00 { get => []; set { } }
}
";

            var ilAssemblyReference = TestReferences.SymbolsTests.CustomModifiers.Modifiers.dll;

            var comp = CreateCompilation(text, new MetadataReference[] { ilAssemblyReference });
            var global = comp.GlobalNamespace;

            comp.VerifyEmitDiagnostics();

            var @class = global.GetMember<NamedTypeSymbol>("Derived");

            for (int i = 0; i < 0x4; i++)
            {
                PropertySymbol property = @class.GetMember<PropertySymbol>("Property" + Convert.ToString(i, 2).PadLeft(2, '0'));
                bool inType = (i & 0x2) != 0;
                bool onType = (i & 0x1) != 0;

                CheckPropertyCustomModifiers(property, inType, onType);
                CheckMethodCustomModifiers(
                    property.GetMethod,
                    inReturnType: inType,
                    onReturnType: onType,
                    inParameterType: false,
                    onParameterType: false);
                CheckMethodCustomModifiers(
                    property.SetMethod,
                    inReturnType: false,
                    onReturnType: false,
                    inParameterType: inType,
                    onParameterType: onType);
            }
        }

Failure message:

System.InvalidOperationException : Assertion failed

  Stack Trace: 
ThrowingTraceListener.Fail(String message, String detailMessage) line 26
TraceInternal.Fail(String message)
Debug.Assert(Boolean condition)
LocalRewriter.VisitExpressionImpl(BoundExpression node) line 280
LocalRewriter.Visit(BoundNode node) line 214
BoundTreeRewriter.VisitReturnStatement(BoundReturnStatement node) line 11274
LocalRewriter.VisitReturnStatement(BoundReturnStatement node) line 15
BoundReturnStatement.Accept(BoundTreeVisitor visitor) line 3551
LocalRewriter.VisitStatement(BoundStatement node) line 241
LocalRewriter.VisitPossibleUsingDeclaration(BoundStatement node, ImmutableArray`1 statements, Int32 statementIndex, Boolean& replacedLocalDeclarations) line 123
LocalRewriter.VisitStatementSubList(ArrayBuilder`1 builder, ImmutableArray`1 statements, Int32 startIndex) line 81
LocalRewriter.VisitBlock(BoundBlock node) line 33
BoundBlock.Accept(BoundTreeVisitor visitor) line 3293
LocalRewriter.VisitStatement(BoundStatement node) line 241
LocalRewriter.Rewrite(CSharpCompilation compilation, MethodSymbol method, Int32 methodOrdinal, NamedTypeSymbol containingType, BoundStatement statement, TypeCompilationState compilationState, SynthesizedSubmissionFields previousSubmissionFields, Boolean allowOmissionOfConditionalCalls, MethodInstrumentation instrumentation, DebugDocumentProvider debugDocumentProvider, BindingDiagnosticBag diagnostics, ImmutableArray`1& codeCoverageSpans, Boolean& sawLambdas, Boolean& sawLocalFunctions, Boolean& sawAwaitInExceptionHandler) line 146
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) line 1373
MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) line 1159
MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) line 530
<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0() line 432
<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() line 139
Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
MethodCompiler.WaitForWorkers() line 331
MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) line 160
CSharpCompilation.CompileMethods(CommonPEModuleBuilder moduleBuilder, Boolean emittingPdb, DiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) line 3505
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 2952
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 2893
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 2781
DiagnosticExtensions.GetEmitDiagnostics[TCompilation](TCompilation c, EmitOptions options, IEnumerable`1 manifestResources) line 367
DiagnosticExtensions.VerifyEmitDiagnostics[TCompilation](TCompilation c, EmitOptions options, DiagnosticDescription[] expected) line 356
DiagnosticExtensions.VerifyEmitDiagnostics[TCompilation](TCompilation c, DiagnosticDescription[] expected) line 373
CustomModifierCopyTests.TestPropertyOverrideCombinations_CollectionExpressionConversion() line 405
@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 31, 2024
@RikkiGibson RikkiGibson changed the title Custom modifiers are not copied in array type collection expression conversion Custom modifiers are not copied in array type collection expression lowering May 31, 2024
@jaredpar jaredpar added this to the Backlog milestone Jun 5, 2024
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 26, 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

3 participants