From 7dbd047a7a829507238d7ee84d6ca9a8355d6015 Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Thu, 5 Mar 2026 16:36:18 -0500 Subject: [PATCH 1/3] Support pattern match Span char on constant string --- standard/patterns.md | 1 + 1 file changed, 1 insertion(+) diff --git a/standard/patterns.md b/standard/patterns.md index 6f3b9adad..f96e43701 100644 --- a/standard/patterns.md +++ b/standard/patterns.md @@ -163,6 +163,7 @@ For a constant pattern `P`, its *converted value* is Given a pattern input value *e* and a constant pattern `P` with converted value *v*, - if *e* has integral type or enum type, or a nullable form of one of those, and *v* has integral type, the pattern `P` *matches* the value *e* if result of the expression `e == v` is `true`; otherwise +- if *e* is of type `System.Span` or `System.ReadOnlySpan`, and *v* is a constant string, and *v* does not have a constant value of `null`, then the pattern is considered matching if `System.MemoryExtensions.SequenceEqual(e, System.MemoryExtensions.AsSpan(v))` returns `true`; otherwise - the pattern `P` *matches* the value *e* if `object.Equals(e, v)` returns `true`. > *Example*: The `switch` statement in the following method uses five constant patterns in its case labels. From 424df76fc0c2a3b98137023624df3a3aeae2b77c Mon Sep 17 00:00:00 2001 From: Rex Jaeschke Date: Thu, 5 Mar 2026 16:42:05 -0500 Subject: [PATCH 2/3] Support pattern match Span char on constant string --- standard/standard-library.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/standard/standard-library.md b/standard/standard-library.md index 5f42ac8ac..0de83e7a0 100644 --- a/standard/standard-library.md +++ b/standard/standard-library.md @@ -404,6 +404,15 @@ namespace System public abstract class FormattableString : IFormattable { } + public static class MemoryExtensions + { + public static ReadOnlySpan AsSpan (this string? text); + public static bool SequenceEqual (this Span span, ReadOnlySpan other) + where T : IEquatable; + public static bool SequenceEqual (this ReadOnlySpan span, + ReadOnlySpan other) where T : IEquatable; + } + public class OperationCanceledException : Exception { public OperationCanceledException(); @@ -1414,6 +1423,7 @@ The following library types are referenced in this specification. The full names - `global::System.IntPtr` - `global::System.InvalidCastException` - `global::System.InvalidOperationException` +- `global::System.MemoryExtensions` - `global::System.NotSupportedException` - `global::System.Nullable` - `global::System.NullReferenceException` From 6d93f6bad30cbd7d2f8c9e09be8b013b2fe82c5d Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 4 May 2026 11:27:14 -0400 Subject: [PATCH 3/3] a couple missing mentions Add a couple missing mentions in rules on Span --- standard/patterns.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/standard/patterns.md b/standard/patterns.md index f96e43701..42c3447da 100644 --- a/standard/patterns.md +++ b/standard/patterns.md @@ -152,7 +152,7 @@ constant_pattern ; ``` -A constant pattern `P` is *applicable to* a type `T` if there is an implicit conversion from the constant expression of `P` to the type `T`. +A constant pattern `P` is *applicable to* a type `T` if there is an implicit conversion from the constant expression of `P` to the type `T`, or if `T` is `System.Span` or `System.ReadOnlySpan` and the constant expression of `P` is of type `string` and is not the `null` literal. For a constant pattern `P`, its *converted value* is @@ -163,7 +163,7 @@ For a constant pattern `P`, its *converted value* is Given a pattern input value *e* and a constant pattern `P` with converted value *v*, - if *e* has integral type or enum type, or a nullable form of one of those, and *v* has integral type, the pattern `P` *matches* the value *e* if result of the expression `e == v` is `true`; otherwise -- if *e* is of type `System.Span` or `System.ReadOnlySpan`, and *v* is a constant string, and *v* does not have a constant value of `null`, then the pattern is considered matching if `System.MemoryExtensions.SequenceEqual(e, System.MemoryExtensions.AsSpan(v))` returns `true`; otherwise +- if *e* is of type `System.Span` or `System.ReadOnlySpan`, and *v* is a constant string, and *v* does not have a constant value of `null`, the pattern `P` *matches* the value *e* if `System.MemoryExtensions.SequenceEqual(e, System.MemoryExtensions.AsSpan(v))` returns `true`; otherwise - the pattern `P` *matches* the value *e* if `object.Equals(e, v)` returns `true`. > *Example*: The `switch` statement in the following method uses five constant patterns in its case labels.