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

Switch expression with mixed type and property patterns results with MSB6006 "csc.exe" exited with code -2146232797 #71660

Closed
piotr-czerwinski opened this issue Jan 16, 2024 · 0 comments · Fixed by #71968
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug
Milestone

Comments

@piotr-czerwinski
Copy link

Version Used: Visual Studio 17.8.4 & 17.9.0 Preview 2.1

Steps to Reproduce: Compilation of one of the following switch expression (in VS or sharplab.io):

 _ = (ICollection)new List<int>() switch
      {
          { Count: 0 } => $"Empty collection",
          IList { Count: 1 } => $"List with a single element",
      }; 
 _ = new List<int>() switch
      {
          ICollection { Count: 0 } => $"Empty collection",
          IList { Count: 1 } => $"List with a single element",
      };

Expected Behavior: Either sucessfull compilation or proper error message

Actual Behavior: MSB6006 "csc.exe" exited with code -2146232797 with no meaningfull message

Sharplab.io exception stack trace provided below:

System.InvalidCastException: Unable to cast object of type 'NumericValueSet`2[System.Int32,Microsoft.CodeAnalysis.CSharp.ValueSetFactory+IntTC]' to type 'NumericValueSet`2[System.Int32,Microsoft.CodeAnalysis.CSharp.ValueSetFactory+NonNegativeIntTC]'.
   at Microsoft.CodeAnalysis.CSharp.ValueSetFactory.NumericValueSet`2.Intersect(IValueSet`1 o)
   at Microsoft.CodeAnalysis.CSharp.ValueSetFactory.NumericValueSet`2.Microsoft.CodeAnalysis.CSharp.IValueSet.Intersect(IValueSet other)
   at Microsoft.CodeAnalysis.CSharp.DecisionDagBuilder.SplitValues(ImmutableDictionary`2 values, BoundDagTest test)
   at Microsoft.CodeAnalysis.CSharp.DecisionDagBuilder.SplitCases(DagState state, BoundDagTest test, FrozenArrayBuilder`1& whenTrue, ImmutableDictionary`2& whenTrueValues, FrozenArrayBuilder`1& whenFalse, ImmutableDictionary`2& whenFalseValues, Boolean& foundExplicitNullTest)
   at Microsoft.CodeAnalysis.CSharp.DecisionDagBuilder.MakeDecisionDag(TemporaryArray`1& casesForRootNode, Dictionary`2 uniqueState)
   at Microsoft.CodeAnalysis.CSharp.DecisionDagBuilder.MakeBoundDecisionDag(SyntaxNode syntax, TemporaryArray`1& cases)
   at Microsoft.CodeAnalysis.CSharp.DecisionDagBuilder.CreateDecisionDagForSwitchExpression(SyntaxNode syntax, BoundExpression switchExpressionInput, ImmutableArray`1 switchArms)
   at Microsoft.CodeAnalysis.CSharp.SwitchExpressionBinder.CheckSwitchExpressionExhaustive(SwitchExpressionSyntax node, BoundExpression boundInputExpression, ImmutableArray`1 switchArms, BoundDecisionDag& decisionDag, LabelSymbol& defaultLabel, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.SwitchExpressionBinder.BindSwitchExpressionCore(SwitchExpressionSyntax node, Binder originalBinder, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindSwitchExpression(SwitchExpressionSyntax node, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindExpressionInternal(ExpressionSyntax node, BindingDiagnosticBag diagnostics, Boolean invoked, Boolean indexed)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindInferredVariableInitializer(BindingDiagnosticBag diagnostics, ExpressionSyntax initializer, BindValueKind valueKind, CSharpSyntaxNode errorSyntax)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindVariableDeclaration(SourceLocalSymbol localSymbol, LocalDeclarationKind kind, Boolean isVar, VariableDeclaratorSyntax declarator, TypeSyntax typeSyntax, TypeWithAnnotations declTypeOpt, AliasSymbol aliasOpt, BindingDiagnosticBag diagnostics, Boolean includeBoundType, CSharpSyntaxNode associatedSyntaxNode)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindDeclarationStatementParts(LocalDeclarationStatementSyntax node, BindingDiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Binder.BindLocalDeclarationStatement(LocalDeclarationStatementSyntax 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.BindStatement(StatementSyntax node, 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.<>c__DisplayClass25_0.<CompileNamedTypeAsync>b__0()
   at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__281_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)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsForAllMethodBodies(BindingDiagnosticBag diagnostics, Boolean doLowering, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetDiagnosticsWithoutFiltering(CompilationStage stage, Boolean includeEarlierStages, BindingDiagnosticBag builder, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.<GetAllDiagnosticsAsync>g__getAllDiagnosticsWithoutStateTrackingAsync|35_0(ImmutableArray`1 analyzers, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetAllDiagnosticsAsync(CancellationToken cancellationToken)
   at MirrorSharp.Internal.Roslyn.RoslynSession.GetDiagnosticsAsync(CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Roslyn\RoslynSession.cs:line 99
   at MirrorSharp.Internal.Handlers.SlowUpdateHandler.ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Handlers\SlowUpdateHandler.cs:line 27
   at MirrorSharp.Internal.Connection.ReceiveAndProcessInternalAsync(CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Connection.cs:line 96
   at MirrorSharp.Internal.Connection.ReceiveAndProcessAsync(CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\source\#external\mirrorsharp\Common\Internal\Connection.cs:line 54
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 16, 2024
@jaredpar jaredpar added area-debugging Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead area-debugging labels Jan 18, 2024
@jaredpar jaredpar added this to the 17.10 milestone Jan 18, 2024
@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants