-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Description
Championed issue: dotnet/csharplang#1881
Proposal: pattern-match-span-of-char-on-string.md
Branch: features/patterns-span-char
Compiler
-
-langver - test pattern matching in:
-
is -
switchexpression -
switchstatement
-
- handle missing well-known type and members:
System.MemoryExtensions - with
Span<char>orReadOnlySpan<char>value:-
default, -
new(null) -
new(new char[0]) -
new("") -
new("...")
-
- with case:
-
null -
default -
(string)null -
default(string) -
"" - shorter than span, longer than span
- different case
- constant interpolated string
-
-
and,or,notwith constant string patterns, property patterns, list patterns - exhaustiveness checks:
- for constant
stringpatterns only - for constant
stringpatterns and other patterns
- for constant
-
obj is ReadOnlySpan<char> and "abc", forobject objandValueType obj - disallow in expression tree
-
[Obsolete] static class MemoryExtensions { ... } - generate string hash function and use in switch rather than separate comparisons when more than 6 cases (see
<PrivateImplementationDetails>.ComputeReadOnlySpanHash()etc.)- hash function with
(string)nullcase
- hash function with
- SemanticModel
-
GetTypeInfo()on constant string case -
GetDeclaredSymbol():chars is "abc" and var xchecking the type ofx
-
-
IOperation - Control Flow Graph
- Add to docs/contributing/Compiler Test Plan.md
IDE
- Convert
iftoswitch
Open questions
- Is case
(string)nullallowed? Is it equivalent to case""? - How to handle generic cases in future?
static bool F<T>(T t) where T : ref struct => t is "str"; - LDM: How much should we care about interaction with list-patterns?
readOnlySPanOfChar switch { [ 'a', .. ] => 0, "abc" => 1 /*unreachable*/ }
Reactions are currently unavailable