Skip to content

Commit 468b05c

Browse files
committed
C#: Expressions of type Span<char> and ReadOnlySpan<char> can be matched against constant strings.
1 parent 2c08b95 commit 468b05c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
class PatternMatchSpan
4+
{
5+
6+
public void M1(ReadOnlySpan<char> x1)
7+
{
8+
if (x1 is "ABC") { }
9+
}
10+
11+
public void M2(Span<char> x2)
12+
{
13+
switch (x2)
14+
{
15+
case "DEF": { break; }
16+
default: { break; }
17+
}
18+
}
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| ReadOnlySpan<Char> | PatternMatchSpan.cs:8:19:8:23 | "ABC" | String |
2+
| Span<Char> | PatternMatchSpan.cs:15:18:15:22 | "DEF" | String |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from PatternMatch pm
4+
where pm.getFile().getStem() = "PatternMatchSpan"
5+
select pm.getExpr().getType().getName(), pm.getPattern(), pm.getPattern().getType().getName()

0 commit comments

Comments
 (0)