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

Partial indexer with an IndexerName attribute causes a crash in compiler #76842

Open
AlekseyTs opened this issue Jan 21, 2025 · 1 comment
Open
Labels
Area-Compilers Bug Feature - Partial Properties untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@AlekseyTs
Copy link
Contributor

https://sharplab.io/#v2:EYLgtghglgdgNAFxFANnAJiA1AHwAIAMABHgIwB0ASgK4wJRgCm5AwgPZgAOqjATgMp8AblADGjAM4BuALAAoeZwi96EFEQkJe1UQiL9S8gN7yiZkgGYiSlVDVFYehAAsoEgNqOiADwC6RIwBzRgQAXgA+bykAX3lTc3cASRh0Rm8+ADkIJgAKACIAWQBPLKY8gEpfeLM8KxtVdS8XN086H38gkJj5WLkgA= :

using System.Runtime.CompilerServices;

partial struct S1
{
    public partial int this[int x] {get=>x;}

    [IndexerName("MyName")]
    public partial int this[int x] {get;}
}

Or https://sharplab.io/#v2:EYLgtghglgdgNAFxFANnAJiA1AHwAIAMABHgIwB0ASgK4wJRgCm5AwgPZgAOqjATgMp8AblADGjAM4BuALAAoeZwi96EFEQkJe1UQiL9S8gN7yiZogG0AkjHSMAHnwByEJgAoARAFkAni6YeAJQAuqbmeADMREoqUGpEsHoIABZQEhaJRPbBREYA5owIALwAfPZSAL7yYWaR0cqq6pkpaRl0WTn5hZXyVXJAA=== :

using System.Runtime.CompilerServices;

partial struct S1
{
    [IndexerName("MyName")]
    public partial int this[int x] {get=>x;}

    public partial int this[int x] {get;}
}

Observed:

System.ArgumentException: adding a duplicate (Parameter 'key')
   at Roslyn.Utilities.ConcurrentDictionaryExtensions.Add[K,V](ConcurrentDictionary`2 dict, K key, V value) in /_/src/Compilers/Core/Portable/InternalUtilities/ConcurrentDictionaryExtensions.cs:line 24
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 1343
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 537
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0() in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 439
   at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() in /_/src/Compilers/Core/Portable/InternalUtilities/UICultureUtilities.cs:line 139
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__292_0(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 160
   at Microsoft.CodeAnalysis.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) in /_/src/Compilers/Core/Portable/Compilation/Compilation.cs:line 2970
@AlekseyTs
Copy link
Contributor Author

#76871 fixes up the partial indexer merge process to a degree that the crash no longer occurs. However, I think a follow up (at least in the form of more targeted testing) is still necessary. For example we need to make sure both parts are consistent in terms of name related information, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Feature - Partial Properties untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

1 participant