Skip to content

C# compiler should compile parenthesized type pattern, which is a part of or-/and-pattern, without errors #49354

@sharctgx

Description

@sharctgx

Version Used:

master branch 11.11.2020

Steps to Reproduce:

Compile and run the following code:

using static System.Console;

void M(object o) {
    switch (o) {
        case (int) or string:
            WriteLine("OK");
            break;
    }
}

M(1);

Expected Behavior:

"OK" is printed.

Actual Behavior:

Compiler produces following errors:

error CS1001: Identifier expected
error CS1002: ; expected
error CS1513: } expected
error CS1513: } expected
error CS1022: Type or namespace definition, or end-of-file expected
error CS1022: Type or namespace definition, or end-of-file expected
error CS1022: Type or namespace definition, or end-of-file expected
error CS0103: The name 'or' does not exist in the current context
error CS0139: No enclosing loop out of which to break or continue
error CS8070: Control cannot fall out of switch from final case label ('case (int) or ')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions