-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2761,6 +2761,39 @@ public static void Test5<T>(T t) where T : IIndexable, ICountableViaLength, ICou | |
); | ||
} | ||
|
||
[Fact, WorkItem(59466, "https://github.com/dotnet/roslyn/issues/59466")] | ||
public void AlwaysTruePattern() | ||
{ | ||
var source = @" | ||
_ = new S() is [..var y]; | ||
_ = new S() is [..]; | ||
_ = new S() is [..[..]]; | ||
_ = new S() is not [..]; | ||
|
||
struct S | ||
{ | ||
public int Length => 1; | ||
public int this[int i] => 42; | ||
public S this[System.Range r] => default; | ||
} | ||
"; | ||
var comp = CreateCompilationWithIndexAndRangeAndSpan(source); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Is the expectation here that user should simplify to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user should simply write |
||
// (3,5): warning CS8794: An expression of type 'S' always matches the provided pattern. | ||
// _ = new S() is [..]; | ||
Diagnostic(ErrorCode.WRN_IsPatternAlways, "new S() is [..]").WithArguments("S").WithLocation(3, 5), | ||
// (4,5): warning CS8794: An expression of type 'S' always matches the provided pattern. | ||
// _ = new S() is [..[..]]; | ||
Diagnostic(ErrorCode.WRN_IsPatternAlways, "new S() is [..[..]]").WithArguments("S").WithLocation(4, 5), | ||
// (5,5): error CS8518: An expression of type 'S' can never match the provided pattern. | ||
// _ = new S() is not [..]; | ||
Diagnostic(ErrorCode.ERR_IsPatternImpossible, "new S() is not [..]").WithArguments("S").WithLocation(5, 5) | ||
); | ||
} | ||
|
||
[Fact] | ||
public void ListPattern_ValEscape() | ||
{ | ||
|
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.