Skip to content

Commit 8eb89cf

Browse files
committed
C#: Add test and expected output.
1 parent 74cb1ea commit 8eb89cf

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
7+
public class MyClass
8+
{
9+
public void M1()
10+
{
11+
var y = 4;
12+
int[] x1 = [1 + 4, 2, 8];
13+
Span<int> x2 = [3, y];
14+
int[] all = [.. x1, .. x2];
15+
int[][] jagged = [[1, y], x1];
16+
int[] nested = [1, .. (int[])[.. x1]];
17+
IntegerCollection collection = [4, y, 9, .. x1];
18+
M2([1, 2, 3]);
19+
}
20+
21+
public static void M2(Span<int> x) { }
22+
23+
public static void M2(ReadOnlySpan<int> x) { }
24+
}
25+
26+
[System.Runtime.CompilerServices.CollectionBuilder(typeof(IntegerCollectionBuilder), "Create")]
27+
public class IntegerCollection : IEnumerable<int>
28+
{
29+
private int[] items;
30+
31+
public IntegerCollection(ReadOnlySpan<int> items)
32+
{
33+
this.items = items.ToArray();
34+
}
35+
36+
public IEnumerator<int> GetEnumerator() => items.AsEnumerable<int>().GetEnumerator();
37+
38+
IEnumerator IEnumerable.GetEnumerator() => items.GetEnumerator();
39+
}
40+
41+
public static class IntegerCollectionBuilder
42+
{
43+
public static IntegerCollection Create(ReadOnlySpan<int> elements)
44+
=> new IntegerCollection(elements);
45+
}
46+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
| CollectionExpressions.cs:12:20:12:32 | [...] | Int32[] | 0 | CollectionExpressions.cs:12:21:12:25 | ... + ... |
2+
| CollectionExpressions.cs:12:20:12:32 | [...] | Int32[] | 1 | CollectionExpressions.cs:12:28:12:28 | 2 |
3+
| CollectionExpressions.cs:12:20:12:32 | [...] | Int32[] | 2 | CollectionExpressions.cs:12:31:12:31 | 8 |
4+
| CollectionExpressions.cs:13:24:13:29 | [...] | Span<Int32> | 0 | CollectionExpressions.cs:13:25:13:25 | 3 |
5+
| CollectionExpressions.cs:13:24:13:29 | [...] | Span<Int32> | 1 | CollectionExpressions.cs:13:28:13:28 | access to local variable y |
6+
| CollectionExpressions.cs:14:21:14:34 | [...] | Int32[] | 0 | CollectionExpressions.cs:14:22:14:26 | .. access to local variable x1 |
7+
| CollectionExpressions.cs:14:21:14:34 | [...] | Int32[] | 1 | CollectionExpressions.cs:14:29:14:33 | .. access to local variable x2 |
8+
| CollectionExpressions.cs:15:26:15:37 | [...] | Int32[][] | 0 | CollectionExpressions.cs:15:27:15:32 | [...] |
9+
| CollectionExpressions.cs:15:26:15:37 | [...] | Int32[][] | 1 | CollectionExpressions.cs:15:35:15:36 | access to local variable x1 |
10+
| CollectionExpressions.cs:15:27:15:32 | [...] | Int32[] | 0 | CollectionExpressions.cs:15:28:15:28 | 1 |
11+
| CollectionExpressions.cs:15:27:15:32 | [...] | Int32[] | 1 | CollectionExpressions.cs:15:31:15:31 | access to local variable y |
12+
| CollectionExpressions.cs:16:24:16:45 | [...] | Int32[] | 0 | CollectionExpressions.cs:16:25:16:25 | 1 |
13+
| CollectionExpressions.cs:16:24:16:45 | [...] | Int32[] | 1 | CollectionExpressions.cs:16:28:16:44 | .. (...) ... |
14+
| CollectionExpressions.cs:16:38:16:44 | [...] | Int32[] | 0 | CollectionExpressions.cs:16:39:16:43 | .. access to local variable x1 |
15+
| CollectionExpressions.cs:17:40:17:55 | [...] | IntegerCollection | 0 | CollectionExpressions.cs:17:41:17:41 | 4 |
16+
| CollectionExpressions.cs:17:40:17:55 | [...] | IntegerCollection | 1 | CollectionExpressions.cs:17:44:17:44 | access to local variable y |
17+
| CollectionExpressions.cs:17:40:17:55 | [...] | IntegerCollection | 2 | CollectionExpressions.cs:17:47:17:47 | 9 |
18+
| CollectionExpressions.cs:17:40:17:55 | [...] | IntegerCollection | 3 | CollectionExpressions.cs:17:50:17:54 | .. access to local variable x1 |
19+
| CollectionExpressions.cs:18:12:18:20 | [...] | ReadOnlySpan<Int32> | 0 | CollectionExpressions.cs:18:13:18:13 | 1 |
20+
| CollectionExpressions.cs:18:12:18:20 | [...] | ReadOnlySpan<Int32> | 1 | CollectionExpressions.cs:18:16:18:16 | 2 |
21+
| CollectionExpressions.cs:18:12:18:20 | [...] | ReadOnlySpan<Int32> | 2 | CollectionExpressions.cs:18:19:18:19 | 3 |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from CollectionExpression ce, Expr element, int i
4+
where element = ce.getElement(i)
5+
select ce, ce.getType().toString(), i.toString(), element
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj

0 commit comments

Comments
 (0)