-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Report ERR_PatternWrongType for Union matching scenarios #81352
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
Conversation
| // (102,25): error CS8121: An expression of type 'S1' cannot be handled by a pattern of type 'C4'. | ||
| // _ = u is C1 and C4; | ||
| Diagnostic(ErrorCode.ERR_PatternWrongType, "C4").WithArguments("S1", "C4").WithLocation(102, 25), | ||
| // (103,24): error CS8121: An expression of type 'S1' cannot be handled by a pattern of type 'C4'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we should also take a look at improving the diagnostics for these cases too. It's not obvious to me from reading the message that the problem is "'C4' is not part of the union 'S1'". #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we shoudl also take a look at improving the diagnostics for these cases too. It's not obvious to me from reading the message that the problem is "'C4' is not part of the union 'S1'".
I think already added PROTOTYPE comment will cover this as well.
|
@RikkiGibson, @333fred, @dotnet/roslyn-compiler Please review |
333fred
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small test suggestion, otherwise LGTM
|
@RikkiGibson, @dotnet/roslyn-compiler For a second review |
|
@RikkiGibson, @dotnet/roslyn-compiler For a second review |
| if (match == ConstantValue.False || match == ConstantValue.Bad) | ||
| { | ||
| diagnostics.Add(ErrorCode.ERR_PatternWrongType, expression.Syntax.Location, unionType, expression.Display); | ||
| hasErrors = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like hasErrors is used after being assigned here, was that intentional? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like hasErrors is used after being assigned here, was that intentional?
Yes, a copy/paste artifact. I'll remove this assignment (probably in the next PR)
Relates to test plan: #81074