Skip to content

Commit 2bbd555

Browse files
committed
C#: Add tests for C# 7.3 features.
1 parent 5596bc8 commit 2bbd555

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ArrayCreation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class ArrayCreation<SyntaxNode> : Expression<SyntaxNode> where SyntaxNo
99
protected ArrayCreation(ExpressionNodeInfo info) : base(info) { }
1010
}
1111

12-
abstract class ExplicitArrayCreation<T> : ArrayCreation<T> where T:ExpressionSyntax
12+
abstract class ExplicitArrayCreation<SyntaxNode> : ArrayCreation<SyntaxNode> where SyntaxNode : ExpressionSyntax
1313
{
1414
protected ExplicitArrayCreation(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.ARRAY_CREATION)) { }
1515

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| csharp73.cs:9:20:9:49 | array creation of type Char* | 0 | csharp73.cs:9:20:9:49 | 2 |
2+
| csharp73.cs:10:20:10:45 | array creation of type Char* | 0 | csharp73.cs:10:36:10:36 | 1 |
3+
| csharp73.cs:11:20:11:37 | array creation of type Char[] | 0 | csharp73.cs:11:20:11:37 | 1 |
4+
| csharp73.cs:12:20:12:38 | array creation of type Char* | 0 | csharp73.cs:12:36:12:37 | 10 |
5+
| csharp73.cs:13:20:13:31 | array creation of type Char[] | 0 | csharp73.cs:13:29:13:30 | 10 |
6+
| csharp73.cs:21:23:21:33 | array creation of type Int32[] | 0 | csharp73.cs:21:31:21:32 | 10 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import csharp
2+
3+
from ArrayCreation creation, int i
4+
select creation, i, creation.getLengthArgument(i)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| csharp73.cs:9:20:9:49 | array creation of type Char* | 0 | csharp73.cs:9:40:9:42 | x |
2+
| csharp73.cs:9:20:9:49 | array creation of type Char* | 1 | csharp73.cs:9:45:9:47 | y |
3+
| csharp73.cs:10:20:10:45 | array creation of type Char* | 0 | csharp73.cs:10:41:10:43 | x |
4+
| csharp73.cs:11:20:11:37 | array creation of type Char[] | 0 | csharp73.cs:11:33:11:35 | x |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import csharp
2+
3+
from ArrayCreation array, int i
4+
select array, i, array.getInitializer().getElement(i)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// semmle-extractor-options: /langversion:latest
2+
3+
using System;
4+
5+
class StackAllocs
6+
{
7+
unsafe void Fn()
8+
{
9+
var arr1 = stackalloc char[] { 'x', 'y' };
10+
var arr2 = stackalloc char[1] { 'x' };
11+
var arr3 = new char[] { 'x' };
12+
var arr4 = stackalloc char[10];
13+
var arr5 = new char[10];
14+
}
15+
}
16+
17+
class PinnedReference
18+
{
19+
unsafe void F()
20+
{
21+
Span<int> t = new int[10];
22+
// This line should compile and generate a call to t.GetPinnableReference()
23+
// fixed (int * p = t)
24+
{
25+
}
26+
}
27+
}
28+
29+
class UnmanagedConstraint<T> where T : unmanaged
30+
{
31+
}
32+
33+
class EnumConstraint<T> where T : System.Enum
34+
{
35+
}
36+
37+
class DelegateConstraint<T> where T : System.Delegate
38+
{
39+
}
40+
41+
class ExpressionVariables
42+
{
43+
ExpressionVariables(out int x)
44+
{
45+
x = 5;
46+
}
47+
48+
public ExpressionVariables() : this(out int x)
49+
{
50+
Console.WriteLine($"x is {x}");
51+
}
52+
}

0 commit comments

Comments
 (0)