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

Trying to jump out of local function after a using declaration causes internal error: 'given key was not present in dictionary' #73397

Closed
vsfeedback opened this issue May 9, 2024 · 3 comments · Fixed by #73402
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
I had this issue after copy-pasting some stuff, creating a piece of (nonsense) code that caused many internal errors.

I managed to create a smaller piece of code that still reproduces the same error:

using System;

internal class Program
{
	static void Main()
	{
	foo:
		void Bar()
		{
			using var obj = (IDisposable)null!; // casting null to an IDisposable is for demonstration purposes
			goto foo;
		}
	}
}

After writing that, multiple banners appear saying that Feature X is currently unavailable due to an internal error.
image.png

It seems that trying to jump to an unreachable label from a point after a using declaration causes errors with the following stacktrace:

StreamJsonRpc.RemoteInvocationException: The given key 'foo' was not present in the dictionary.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__151`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__22`1.MoveNext()
RPC server exception:
System.Collections.Generic.KeyNotFoundException: The given key 'foo' was not present in the dictionary.
      at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.VisitGotoStatement(BoundGotoStatement node)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.Visit(BoundNode node)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.VisitStatement(BoundStatement statement)
      at Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.VisitStatements(ImmutableArray`1 statements)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.VisitBlock(BoundBlock node)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.Visit(BoundNode node)
      at Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.Scan(Boolean& badRegion)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.Scan(Boolean& badRegion)
      at Microsoft.CodeAnalysis.CSharp.AbstractFlowPass`2.Analyze(Boolean& badRegion, Optional`1 initialState)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.Analyze(Boolean& badRegion, DiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.Analyze(CSharpCompilation compilation, Symbol member, BoundBlock block, DiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.<BindLocalFunctionStatement>g__runAnalysis|876_0(BoundBlock block, BindingDiagnosticBag blockDiagnostics, <>c__DisplayClass876_0&)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindLocalFunctionStatement(LocalFunctionStatementSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindLabeled(LabeledStatementSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindBlockParts(BlockSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindBlock(BlockSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindStatement(StatementSyntax node, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindMethodBody(CSharpSyntaxNode declaration, BlockSyntax blockBody, ArrowExpressionClauseSyntax expressionBody, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.Binder.BindMethodBody(CSharpSyntaxNode syntax, BindingDiagnosticBag diagnostics)
      at Microsoft.CodeAnalysis.CSharp.MethodCompiler.BindMethodBody(MethodSymbol method, TypeCompilationState compilationState, BindingDiagnosticBag diagnostics, Boolean includeInitializersInBody, BoundNode initializersBody, Boolean reportNullableDiagnostics, ImportChain& importChain, Boolean& originalBodyNested, Boolean& prependedDefaultValueTypeConstructorInitializer, InitialState& forSemanticModel)
      at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState)
      at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType)
      at Microsoft.CodeAnalysis.CSharp.MethodCompiler.VisitNamedType(NamedTypeSymbol symbol, TypeCompilationState arg)
      at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamespace(NamespaceSymbol symbol)
      at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.<GetDiagnosticsForMethodBodiesInTree>g__compileMethodBodiesAndDocComments|226_0(SyntaxTree filterTree, Nullable`1 filterSpan, BindingDiagnosticBag bindingDiagnostics, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForMethodBodiesInTree(SyntaxTree tree, Nullable`1 span, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForSyntaxTree(CompilationStage stage, SyntaxTree syntaxTree, Nullable`1 filterSpanWithinTree, Boolean includeEarlierStages, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetDiagnostics(Nullable`1 span, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.AddImport.AbstractAddImportFeatureService`1.GetUniqueFixesAsyncInCurrentProcessAsync(Document document, TextSpan span, ImmutableArray`1 diagnosticIds, ISymbolSearchService symbolSearchService, AddImportOptions options, ImmutableArray`1 packageSources, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.AddImport.AbstractAddImportFeatureService`1.GetUniqueFixesAsync(Document document, TextSpan span, ImmutableArray`1 diagnosticIds, ISymbolSearchService symbolSearchService, AddImportOptions options, ImmutableArray`1 packageSources, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteMissingImportDiscoveryService.<>c__DisplayClass4_0.<<GetUniqueFixesAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass9_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)


Original Comments

Feedback Bot on 5/6/2024, 01:49 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@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 9, 2024
@dibarbet
Copy link
Member

dibarbet commented May 9, 2024

Reproducible via a dotnet build as well

C:\Program Files\dotnet\sdk\8.0.300\Roslyn\Microsoft.CSharp.Core.targets(85,5): error : Process terminated. System.Collections.Generic.KeyNotFoundException: The given key 'foo' was not present in the dictionary. [C:\Users\dabarbet\source\repo
s\trash\CompilerCrash\CompilerCrash.csproj]
C:\Program Files\dotnet\sdk\8.0.300\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at System.Collections.Generic.Dictionary`2.get_Item(TKey key) [C:\Users\dabarbet\source\repos\trash\CompilerCrash\CompilerCrash.csproj]
C:\Program Files\dotnet\sdk\8.0.300\Roslyn\Microsoft.CSharp.Core.targets(85,5): error :    at Microsoft.CodeAnalysis.CSharp.ControlFlowPass.VisitGotoStatement(BoundGotoStatement node) [C:\Users\dabarbet\source\repos\trash\CompilerCrash\Compil
erCrash.csproj]
...truncated

@dibarbet
Copy link
Member

dibarbet commented May 9, 2024

@jjonescz can you confirm if this is a duplicate of #73068

@jjonescz
Copy link
Contributor

jjonescz commented May 9, 2024

Yes, this is a duplicate, but I will add tests for local functions as well.

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

Successfully merging a pull request may close this issue.

3 participants