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

Compiler crash in pattern matching lowering - Error MSB6006: "csc.exe" exited with code -2146232797. (1, 1) #51801

Closed
TessenR opened this issue Mar 11, 2021 · 2 comments · Fixed by #56586
Assignees
Milestone

Comments

@TessenR
Copy link

TessenR commented Mar 11, 2021

Version Used:

Microsoft Visual Studio Professional 2019 Preview
Version 16.10.0 Preview 1.0
VisualStudio.16.Preview/16.10.0-pre.1.0+31025.218
Microsoft .NET Framework
Version 4.8.04084

Steps to Reproduce:

Compile the following code

class Base
{
  public virtual bool IsOk { get { return true; } set { } }
}

class C : Base
{
  public override bool IsOk { set { } }
  public string? Value { get; }

  public string M()
  {
    switch (this)
    {
      case { IsOk: true }:
        return Value;
      default:
        return Value;
    }
  }
}

Expected Behavior:
Either the code compiles or there's a compilation error somewhere in the code (probably on the case { IsOk: true }:)

Actual Behavior:
Error MSB6006: "csc.exe" exited with code -2146232797. (1, 1)

Notes
This example on sharplab.io gives the following exception:

System.NullReferenceException: Object reference not set to an instance of an object.

   at Microsoft.CodeAnalysis.CSharp.SyntheticBoundNodeFactory.Call(BoundExpression receiver, MethodSymbol method, ImmutableArray`1 args) in /_/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs:line 741

   at Microsoft.CodeAnalysis.CSharp.SyntheticBoundNodeFactory.Call(BoundExpression receiver, MethodSymbol method) in /_/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs:line 716

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.PatternLocalRewriter.LowerEvaluation(BoundDagEvaluation evaluation) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.PatternLocalRewriter.cs:line 155

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.DecisionDagRewriter.LowerDecisionDagNode(BoundDecisionDagNode node, BoundDecisionDagNode nextNode) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.DecisionDagRewriter.cs:line 962

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.DecisionDagRewriter.LowerDecisionDagCore(BoundDecisionDag decisionDag) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.DecisionDagRewriter.cs:line 419

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.BaseSwitchLocalRewriter.LowerDecisionDag(BoundDecisionDag decisionDag) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BasePatternSwitchLocalRewriter.cs:line 70

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.SwitchStatementLocalRewriter.LowerSwitchStatement(BoundSwitchStatement node) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs:line 108

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.SwitchStatementLocalRewriter.Rewrite(LocalRewriter localRewriter, BoundSwitchStatement node) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs:line 32

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitSwitchStatement(BoundSwitchStatement node) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PatternSwitchStatement.cs:line 17

   at Microsoft.CodeAnalysis.CSharp.BoundSwitchStatement.Accept(BoundTreeVisitor visitor) in /_/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs:line 3357

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitStatement(BoundStatement node) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs:line 193

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitPossibleUsingDeclaration(BoundStatement node, ImmutableArray`1 statements, Int32 statementIndex, Boolean& replacedLocalDeclarations) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs:line 100

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitStatementSubList(ArrayBuilder`1 builder, ImmutableArray`1 statements, Int32 startIndex) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs:line 57

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitBlock(BoundBlock node) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Block.cs:line 44

   at Microsoft.CodeAnalysis.CSharp.BoundBlock.Accept(BoundTreeVisitor visitor) in /_/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs:line 2867

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitStatement(BoundStatement node) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs:line 193

   at Microsoft.CodeAnalysis.CSharp.LocalRewriter.Rewrite(CSharpCompilation compilation, MethodSymbol method, Int32 methodOrdinal, NamedTypeSymbol containingType, BoundStatement statement, TypeCompilationState compilationState, SynthesizedSubmissionFields previousSubmissionFields, Boolean allowOmissionOfConditionalCalls, Boolean instrumentForDynamicAnalysis, ImmutableArray`1& dynamicAnalysisSpans, DebugDocumentProvider debugDocumentProvider, BindingDiagnosticBag diagnostics, Boolean& sawLambdas, Boolean& sawLocalFunctions, Boolean& sawAwaitInExceptionHandler) in /_/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs:line 137

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.LowerBodyOrInitializer(MethodSymbol method, Int32 methodOrdinal, BoundStatement body, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState, Boolean instrumentForDynamicAnalysis, DebugDocumentProvider debugDocumentProvider, ImmutableArray`1& dynamicAnalysisSpans, BindingDiagnosticBag diagnostics, VariableSlotAllocator& lazyVariableSlotAllocator, ArrayBuilder`1 lambdaDebugInfoBuilder, ArrayBuilder`1 closureDebugInfoBuilder, StateMachineTypeSymbol& stateMachineTypeOpt) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 1431

   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 917

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 524

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass23_0.<CompileNamedTypeAsync>b__0() in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 420

   at Roslyn.Utilities.UICultureUtilities.<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() in /_/src/Compilers/Core/Portable/InternalUtilities/UICultureUtilities.cs:line 141

   at System.Threading.Tasks.Task.InnerInvoke()

   at System.Threading.Tasks.Task.<>c.<.cctor>b__277_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.WaitForWorkers() in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 329

   at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethodBodies(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuiltOpt, Boolean emittingPdb, Boolean emitTestCoverageData, Boolean hasDeclarationErrors, Boolean emitMethodBodies, BindingDiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs:line 128

   at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CompileMethods(CommonPEModuleBuilder moduleBuilder, Boolean emittingPdb, Boolean emitMetadataOnly, Boolean emitTestCoverageData, DiagnosticBag diagnostics, Predicate`1 filterOpt, CancellationToken cancellationToken) in /_/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs:line 3091

   at Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream metadataPEStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, Boolean useRawWin32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Nullable`1 pdbOptionsBlobReader, CompilationTestData testData, CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/Compilation/Compilation.cs:line 2617

   at Microsoft.CodeAnalysis.Compilation.Emit(Stream peStream, Stream pdbStream, Stream xmlDocumentationStream, Stream win32Resources, Boolean useRawWin32Resources, IEnumerable`1 manifestResources, EmitOptions options, IMethodSymbol debugEntryPoint, Stream sourceLinkStream, IEnumerable`1 embeddedTexts, Stream metadataPEStream, Nullable`1 pdbOptionsBlobReader, CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/Compilation/Compilation.cs:line 2569

   at SharpLab.Server.Compilation.Compiler.TryCompileToStreamAsync(MemoryStream assemblyStream, MemoryStream symbolStream, IWorkSession session, IList`1 diagnostics, CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\!roslyn-branches\dotnet-main\sharplab\source\Server\Compilation\Compiler.cs:line 31

   at SharpLab.Server.MirrorSharp.SlowUpdate.ProcessAsync(IWorkSession session, IList`1 diagnostics, CancellationToken cancellationToken) in D:\a\SharpLab\SharpLab\!roslyn-branches\dotnet-main\sharplab\source\Server\MirrorSharp\SlowUpdate.cs:line 110

   at MirrorSharp.Internal.Handlers.SlowUpdateHandler.ExecuteAsync(AsyncData data, WorkSession session, ICommandResultSender sender, CancellationToken cancellationToken)

   at MirrorSharp.Internal.Connection.ReceiveAndProcessInternalAsync(CancellationToken cancellationToken)

   at MirrorSharp.Internal.Connection.ReceiveAndProcessAsync(CancellationToken cancellationToken)
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 11, 2021
@RikkiGibson
Copy link
Contributor

Very likely that we are not correctly obtaining the get accessor symbol for the property.

@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 15, 2021
@jaredpar jaredpar added the Feature - Pattern Matching Pattern Matching label Mar 15, 2021
@jaredpar jaredpar added this to the 16.10 milestone Mar 15, 2021
@jinujoseph jinujoseph modified the milestones: 16.10, 17.0 Jul 16, 2021
@RikkiGibson
Copy link
Contributor

RikkiGibson commented Sep 21, 2021

I think an analogous bug exists for list patterns when an indexer lacks an override of a get accessor. I will add it to #51289.

I think this test should be added, although I could be wrong about the details, and of course a baseline needs to be included:

        [Fact, WorkItem(51801, "https://github.com/dotnet/roslyn/issues/51801")]
        public void IndexerOverrideLacksAccessor()
        {
            var source = @"
#nullable enable

class Base
{
  public virtual object this[int i] { get { return 1; } set { } }
}

class C : Base
{
  public override object this[int i] { set { } }
  public int Length => 1;

  public string Value { get; }

  public string M()
  {
    switch (this)
    {
      case [1]:
        return Value;
      default:
        return Value;
    }   
  }
}
";
            var verifier = CompileAndVerify(source);
            verifier.VerifyIL("C.M", @"");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants