-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
List-patterns: list-patterns may be always-true #59478
Conversation
comp.VerifyEmitDiagnostics( | ||
// (2,5): warning CS8794: An expression of type 'S' always matches the provided pattern. | ||
// _ = new S() is [..var y]; | ||
Diagnostic(ErrorCode.WRN_IsPatternAlways, "new S() is [..var y]").WithArguments("S").WithLocation(2, 5), |
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.
Is the expectation here that user should simplify to var y
?
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.
The user should simply write is var y
(which would not warn).
List and slice patterns make assumptions about collections being well-behaved. If you grab the entire range, you should get the same collection, so that dicing wasn't necessary.
public void AlwaysTruePattern() | ||
{ | ||
var source = @" | ||
_ = new S() is [..var y]; |
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.
I think you could verify y
is definitely assigned after this statement.
Fixes #59466
Relates to test plan #51289
FYI @alrz