Report ERR_PatternWrongType for Union matching scenarios#81352
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.
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.
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.
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.
It doesn't look like hasErrors is used after being assigned here, was that intentional? #Resolved
There was a problem hiding this comment.
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