Skip to content

Test plan for pattern matching on ReadOnlySpan<char> #59191

@cston

Description

@cston

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
    • switch expression
    • switch statement
  • handle missing well-known type and members: System.MemoryExtensions
  • with Span<char> or ReadOnlySpan<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, not with constant string patterns, property patterns, list patterns
  • exhaustiveness checks:
    • for constant string patterns only
    • for constant string patterns and other patterns
  • obj is ReadOnlySpan<char> and "abc", for object obj and ValueType 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)null case
  • SemanticModel
    • GetTypeInfo() on constant string case
    • GetDeclaredSymbol(): chars is "abc" and var x checking the type of x
  • IOperation
  • Control Flow Graph
  • Add to docs/contributing/Compiler Test Plan.md

IDE

  • Convert if to switch

Open questions

  • Is case (string)null allowed? 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*/ }

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions