-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Pattern matching an enum using an enum value following by using "with expression" on a record causes a compilation error #75074
Comments
I have also found issues when using the linq query syntax enum E { A, B }
record R(int E) { }
static class TestClass
{
public static IEnumerable<R> TestMethod(E testEnum, R[] records) =>
testEnum is E.A
? from item in records
select item
: records;
} Which produces the following errors
|
See #66841 (comment) In short, because you defined a property named C# compiler will make |
This is only a snippet to replicate it in a standalone solution and only applies to the preview compiler. In the actual solution where I hit these issues the names do not overlap. The enum E { A, B }
record R(int E) { }
static class TestClass
{
public static IEnumerable<R> TestMethod(E testEnum, R[] records) =>
testEnum is (E.A)
? from item in records
select item
: records;
} This will build successfully. Note if you create a console app with that code you will still get the error even if you the property from |
This compiles fine because you don't have a type also called Please note that brackets like To make an confliction, just declare a constant and a type, and both named same within a same scope. |
There is nothing to do with semantics here, this is purely a parser regression introduced in #72805. It doesn't matter what additional types or variables you declare: the expression just isn't parsed correctly and produces a syntax error |
Version Used:
Visual Studio 17.12.0 Preview 2.0
DotNet 9.0.100-rc.1.24452.12
Steps to Reproduce:
Create a console app with just this snippet
Diagnostic Id:
Expected Behavior:
Code would compile as it does using stable compiler
Actual Behavior:
Errors as shown above
The text was updated successfully, but these errors were encountered: