question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot compile some condition of switch expression

See original GitHub issue

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

Related Developer Community post: https://developercommunity.visualstudio.com/content/problem/1161747/visual-studio-2019-professional-1672-doesnt-build.html

Duplicate issue: #46877 Duplicate issue: #46990 Duplicate issue: #46899 Duplicate issue: dotnet/core#5087 Duplicate issue: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1179705


[severity:I’m unable to use this version of Visual Studio] [regression] [worked-in:‘16.6.3’] Simply some switch expression code cannot be compiled due to compiler crash. I don’t know what conditions occur this, but I already have 100% repro code. Repro code is here:

using System;

namespace SwitchExpressionBug
{
    public enum EnumA { A, B, C }

    public enum EnumB { X, Y, Z }

    public class Class1
    {
        public string Repro(EnumA a, EnumB b)
            => (a, b) switch
            {
                (EnumA.A, EnumB.X) => "AX",
                (_, EnumB.Y) => "_Y",
                (EnumA.B, EnumB.X) => "BZ",
                (_, EnumB.Z) => "_Z",
                (_, _) => throw new ArgumentException()
            };
    }
}

Visual Studio build result:

1>------ Rebuild All started: Project: SwitchExpressionBug, Configuration: Debug Any CPU ------
1>You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(59,5): error MSB6006: "csc.exe" exited with code -2146232797.
1>Done building project "SwitchExpressionBug.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

.NET 5.0 SDK 5.0.100-preview.6.20318.15

$ dotnet build
Microsoft (R) Build Engine version 16.7.0-preview-20310-07+ee1c9fd0c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : Process terminated. System.NullReferenceException: Object reference not set to an instance of an object. [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.ShortenBranches(Int32& delta) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ComputeOffsetsAndAdjustBranches() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans, AsyncForwardEntryPoint entryPointOpt) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Environment.FailFast(System.String, System.Exception) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.FatalError.Report(System.Exception, System.Action`1<System.Exception>) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.FatalError.ReportUnlessCanceled(System.Exception) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder+BasicBlock.ShortenBranches(Int32 ByRef) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ComputeOffsetsAndAdjustBranches() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, Microsoft.CodeAnalysis.CSharp.BoundStatement, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.LambdaDebugInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.ClosureDebugInfo>, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator, Microsoft.CodeAnalysis.DiagnosticBag, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain, Boolean, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.SourceSpan>, AsyncForwardEntryPoint) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, ProcessedFieldInitializers ByRef, Microsoft.CodeAnalysis.CSharp.SynthesizedSubmissionFields, Microsoft.CodeAnalysis.CSharp.TypeCompilationState) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Roslyn.Utilities.UICultureUtilities+<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.InnerInvoke() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task+<>c.<.cctor>b__276_0(System.Object) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.ExecuteFromThreadPool(System.Threading.Thread) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.ThreadPoolWorkQueue.Dispatch() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : System.NullReferenceException: Object reference not set to an instance of an object. [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.ShortenBranches(Int32& delta) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ComputeOffsetsAndAdjustBranches() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans, AsyncForwardEntryPoint entryPointOpt) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : Process terminated. System.NullReferenceException: Object reference not set to an instance of an object. [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.ShortenBranches(Int32& delta) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ComputeOffsetsAndAdjustBranches() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans, AsyncForwardEntryPoint entryPointOpt) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Environment.FailFast(System.String, System.Exception) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.FatalError.Report(System.Exception, System.Action`1<System.Exception>) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.FatalError.ReportUnlessCanceled(System.Exception) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder+BasicBlock.ShortenBranches(Int32 ByRef) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ComputeOffsetsAndAdjustBranches() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(Microsoft.CodeAnalysis.CSharp.Emit.PEModuleBuilder, Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, Microsoft.CodeAnalysis.CSharp.BoundStatement, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.LambdaDebugInfo>, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.ClosureDebugInfo>, Microsoft.CodeAnalysis.CSharp.StateMachineTypeSymbol, Microsoft.CodeAnalysis.CodeGen.VariableSlotAllocator, Microsoft.CodeAnalysis.DiagnosticBag, Microsoft.CodeAnalysis.CodeGen.DebugDocumentProvider, Microsoft.CodeAnalysis.CSharp.ImportChain, Boolean, Boolean, System.Collections.Immutable.ImmutableArray`1<Microsoft.CodeAnalysis.CodeGen.SourceSpan>, AsyncForwardEntryPoint) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(Microsoft.CodeAnalysis.CSharp.Symbols.MethodSymbol, Int32, ProcessedFieldInitializers ByRef, Microsoft.CodeAnalysis.CSharp.SynthesizedSubmissionFields, Microsoft.CodeAnalysis.CSharp.TypeCompilationState) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(Microsoft.CodeAnalysis.CSharp.Symbols.NamedTypeSymbol) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler+<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Roslyn.Utilities.UICultureUtilities+<>c__DisplayClass5_0.<WithCurrentUICulture>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.InnerInvoke() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task+<>c.<.cctor>b__276_0(System.Object) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.Tasks.Task.ExecuteFromThreadPool(System.Threading.Thread) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading.ThreadPoolWorkQueue.Dispatch() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error : System.NullReferenceException: Object reference not set to an instance of an object. [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.BasicBlock.ShortenBranches(Int32& delta) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.ComputeOffsetsAndAdjustBranches() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.RealizeBlocks() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CodeGen.ILBuilder.Realize() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.CodeGen.CodeGenerator.GenerateImpl() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.GenerateMethodBody(PEModuleBuilder moduleBuilder, MethodSymbol method, Int32 methodOrdinal, BoundStatement block, ImmutableArray`1 lambdaDebugInfo, ImmutableArray`1 closureDebugInfo, StateMachineTypeSymbol stateMachineTypeOpt, VariableSlotAllocator variableSlotAllocatorOpt, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, ImportChain importChainOpt, Boolean emittingPdb, Boolean emitTestCoverageData, ImmutableArray`1 dynamicAnalysisSpans, AsyncForwardEntryPoint entryPointOpt) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileMethod(MethodSymbol methodSymbol, Int32 methodOrdinal, ProcessedFieldInitializers& processedInitializers, SynthesizedSubmissionFields previousSubmissionFields, TypeCompilationState compilationState) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.CompileNamedType(NamedTypeSymbol containingType) [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.6.20318.15\Roslyn\Microsoft.CSharp.Core.targets(59,5): error :    at Microsoft.CodeAnalysis.CSharp.MethodCompiler.<>c__DisplayClass22_0.<CompileNamedTypeAsync>b__0() [C:\temp\SwitchExpressionBug\SwitchExpressionBug\SwitchExpressionBug.csproj]
    0 Warning(s)
    43 Error(s)

Time Elapsed 00:00:06.03

This could be compiled with Visual Studio 2019 but cannot with Visual Studio 2019 Preview.


Original Comments

Feedback Bot on 7/21/2020, 08:11 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
RikkiGibsoncommented, Aug 28, 2020

The fix for this bug will be available in a 16.7 patch release. Thanks again for reporting.

0reactions
RikkiGibsoncommented, Aug 25, 2020

I found that the bug was introduced in #42313 by checking out its parent commit and running the repro test on it. Not certain what the correct fix is yet. /cc @gafter

Read more comments on GitHub >

github_iconTop Results From Across the Web

Switch statement not compiling
"The switch statement is a mult-way decision that tests whether an expression matches one of a number of constant integer values, and branches ......
Read more >
pattern matching expressions using the switch keyword
The compiler generates an error when a lower switch expression arm can't be chosen because a higher switch expression arm matches all its ......
Read more >
Compiler problem: switch statement
I believe the arduino SWITCH statement has some compile time problems. If I try to declare a boolean variable in a CASE statement...
Read more >
Pattern Matching for switch Expressions and Statements
If a switch expression or statement is exhaustive at compile time but not at run time, then a MatchException is thrown. This can...
Read more >
Definitive Guide To Switch Expressions In Java 13 - nipafx
If you recompile the switch expression against the extended Bool , you get a compile error (the expression is no longer exhaustive). Without ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found