Skip to content

Switch expression crashes compiler in expression-bodied member #35278

@agocke

Description

@agocke

https://developercommunity.visualstudio.com/content/problem/475479/visual-studio-2019-rc-cant-compile-c-80-switch-exp.html

This code fails with an assert in CheckValEscape. Looks like switch expressions are not handled.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    public enum Rainbow
    {
        Red,
        Orange,
        Yellow,
        Blue,
        Indigo,
        Violet
    }

    public ref struct RGBColor
    {
        int _r, _g, _b;

        public int R => _r;
        public int G => _g;
        public int B => _b;

        public RGBColor(int r, int g, int b)
        {
            _r = r;
            _g = g;
            _b = b;
        }
    }

    static void Main(string[] args)
    {
   //     FromRainbow(Rainbow.Red);
    }

    public static RGBColor FromRainbow(Rainbow colorBand) =>
        colorBand switch
    {
        Rainbow.Red => new RGBColor(0xFF, 0x00, 0x00),
        Rainbow.Orange => new RGBColor(0xFF, 0x7F, 0x00),
        Rainbow.Yellow => new RGBColor(0xFF, 0xFF, 0x00),
        Rainbow.Blue => new RGBColor(0x00, 0x00, 0xFF),
        Rainbow.Indigo => new RGBColor(0x4B, 0x00, 0x82),
        Rainbow.Violet => new RGBColor(0x94, 0x00, 0xD3),
        _ => throw null!
    };
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions