-
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
Test Plan for "List Patterns" #51289
Comments
A couple of more scenarios to test: |
Note: Make sure obsoletion errors are correctly reported. |
Do we want to report a subsumption error here? case [1] { .., 1 }:
case [1] { 1, .. }: If so, I'm gonna need to go get more coffee. |
What would be the error? "The slice is unnecessary"? |
A better example: case {1, .., 4}:
case {1, 2, 3, 4}:
// ^ error CS8120: The switch case is unreachable. It has already been handled by a previous case or it is impossible to match. |
That does seem useful, but I don't know how hard that would be to check. |
LDM discussion today (on constant string patterns on |
Closing test plan as completed. Issue with FAR isn't blocking. |
Championed issue: dotnet/csharplang#3435
Specification: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/list-patterns.md
Compilers
Work items:
Scenarios:
inputIsCountable is INotCountable and [..]
(seeListPattern_NotCountableInterface
)inputHasExplicitIListImplAndIsNotListPatternable is IList and [..]
(seeListPattern_ExplicitInterfaceImplementation
)void
orstring
returningLength
,ref
/in
parametersthis[Index i]
indexerthis[Index i, int ignored = 0]
indexerthis[int i, int ignored = 0]
indexerthis[Range r]
indexerthis[Range r, int ignored = 0]
indexerthis[int start, int end, int ignored = 0]
indexerSlicePattern_ExtensionIgnored
)Length
field doesn't count (seeListPattern_LengthFieldNotApplicable
)string
and array types (ranges spec calls out special cases for those, seeListPattern
)TestNormalizeListPattern_*
)this[params Range[] p]
(seeListPattern_Range
)this[params Index[] p]
(seeListPattern_Index
)this[params int[] p]
(seeListPattern_Index
)this[long p]
(seeListPattern_MemberLookup_Index_ErrorCases_4
)Slice(int start, int end, int ignored = 0)
(invalid, seeListPattern_MemberLookup_Range_ErrorCases_3
)this[int start, int end, int ignored = 0]
(invalid, seeListPattern_MemberLookup_Index_ErrorCases_3
)expr[N]
orexpr[^N]
orexpr[N..^M]
(using either explicit or implicit indexer pattern) but not any other.ListPattern_CallerInfo
,ListPattern_Index
)ListPattern_ObsoleteMembers
,ListPattern_ObsoleteAccessors
,ListPattern_IndexAndSliceReturnMissingTypes
Index
andRange
are required but optimized away (seeListPattern_IndexAndRangeAreNecessaryButOptimizedAway
)IndexerOverrideLacksAccessor
)SlicePattern_Misplaced
)this[Index]
orthis[Range]
indexer (seeListPattern_MemberLookup_Fallback_InaccessibleIndexer
)ref
returning indexers (seeListPattern_RefReturns
)Length
property checks interact (seePattern_Nullability_Exhaustiveness
)is { Length: -1 }
or{ Count: -1 } but not both (see
ListPattern_LengthAndCountAreOrthogonal`)Index
type on break (seeLengthPattern_NegativeLengthTest_MissingIndex
)switch { [<10] => ..., [>10] => ...}
(should warn)[0, ..] => ..., [.., not 0] => ..., [var unreachable] => ...
,[null, ..] => ..., [.., not null] => ..., [var unreachable] => ...
[0] => ..., [..[not 0]] => ..., [var unreachable] => ...
[1, 2, 3] => ..., [1, .., 3] => ...
ITuple
(seeListPattern_Tuples
){ .. }
and{ .._ }
, and no slice call for{ 1, 2, .. }
,{ 1, 2, ..var unused }
(like for{ Property: var unused }
) (seeSlicePattern_Subpattern
){ var head, ..var tail }
(no)ListPattern_Tuples
)ListPattern_NullableValueType
,ListPattern_ExplicitInterfaceImplementation
)GetDeclaredSymbol
andGetTypeInfo
on designations (seeListPattern_Symbols_01
)SlicePattern_DefiniteAssignment
)case [var x]:
should givex
the right annotation/state) (PR List patterns: add more tests and fix nullability analysis #53822)ListPattern_Nullability_MaybeNullReceiver
)var
designations (seeListPattern_Nullability
)https://github.com/dotnet/roslyn/issues/57884
)case [null, ..]: case [.., not null]: case [var unreachable]:
)dynamic
receiver (seeListPattern_Dynamic
)ListPattern_ExpressionTree
)Language
...
for slice pattern to work better with collection literals? (answer: no)..
(no nested pattern) versus.. <nested pattern>
Slice
methods withuint
,nint
and other numeric types to make a type indexable/rangeable? (orthogonal and out-of-scope)if (index > 0 && index < xs.Count) { var x = xs[index]; DoSmth(x); }
(out-of-scope){ [0]: ... }
or{ [var x]: ... }
(answer: separate championed issue)length: ...
pattern (answer: not a thing anymore)[ .._ ]
requires a sliceable type, whereas[ 1, .. ]
doesn't (answer: correct){ Length: -1 }
? (answer: initially we thought we'd reduce the break to a warning, but we went back to taking the break) (Open issue: how to mitigate break for length patterns? csharplang#5226)ITuple
interact? (question and comments below: "Should iTuple switch { (1,2,3) => 1, [1,2,3] => 2, _ => 0 } produce an error? ITuple is both countable and indexable.") (answer: no)ListPattern_Exhaustiveness_NestedSlice
) (answer: yes)IDE
..var
or.. var
?) (PR)is string[] [>0]
) (not applicable)..var x
(PR)Length
/Count
/indexers when they're used by list pattern (issue FindAllReferences on Length property or Slice method misses usages in list-patterns #58190)and
oror
if (expr[0] is pattern1&& expr[^1] is pattern2)
The text was updated successfully, but these errors were encountered: