Skip to content

Commit aa45920

Browse files
authored
Merge pull request github#4613 from tamasvajk/feature/csharp9-multiple-discards
C#: C#9 add test cases for discards as lambda/delegate parameters
2 parents 34ffcb5 + 6d95105 commit aa45920

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
public class Discard
4+
{
5+
public void M1()
6+
{
7+
Func<int, int, int> i = (int a, int b) => 42;
8+
i = (_, _) => 42;
9+
i = (int _, int _) => 42;
10+
i = delegate (int _, int _) { return 0; };
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| Discard.cs:7:33:7:52 | (...) => ... | Discard.cs:7:38:7:38 | a |
2+
| Discard.cs:7:33:7:52 | (...) => ... | Discard.cs:7:45:7:45 | b |
3+
| Discard.cs:8:13:8:24 | (...) => ... | Discard.cs:8:14:8:14 | _ |
4+
| Discard.cs:8:13:8:24 | (...) => ... | Discard.cs:8:17:8:17 | _`1 |
5+
| Discard.cs:9:13:9:32 | (...) => ... | Discard.cs:9:18:9:18 | _ |
6+
| Discard.cs:9:13:9:32 | (...) => ... | Discard.cs:9:25:9:25 | _`1 |
7+
| Discard.cs:10:13:10:49 | delegate(...) { ... } | Discard.cs:10:27:10:27 | _ |
8+
| Discard.cs:10:13:10:49 | delegate(...) { ... } | Discard.cs:10:34:10:34 | _`1 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import csharp
2+
3+
from AnonymousFunctionExpr anon
4+
select anon, anon.getAParameter()

csharp/ql/test/library-tests/csharp9/NativeInt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
public class Class1
3+
public class NativeInt
44
{
55
public void M1(int j, uint k)
66
{

csharp/ql/test/library-tests/csharp9/PrintAst.expected

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
1+
Discard.cs:
2+
# 3| [Class] Discard
3+
# 5| 5: [Method] M1
4+
# 5| -1: [TypeMention] Void
5+
# 6| 4: [BlockStmt] {...}
6+
# 7| 0: [LocalVariableDeclStmt] ... ...;
7+
# 7| 0: [LocalVariableDeclAndInitExpr] Func<Int32,Int32,Int32> i = ...
8+
# 7| -1: [TypeMention] Func<Int32, Int32, Int32>
9+
# 7| 1: [TypeMention] int
10+
# 7| 2: [TypeMention] int
11+
# 7| 3: [TypeMention] int
12+
# 7| 0: [LocalVariableAccess] access to local variable i
13+
# 7| 1: [LambdaExpr] (...) => ...
14+
#-----| 2: (Parameters)
15+
# 7| 0: [Parameter] a
16+
# 7| -1: [TypeMention] int
17+
# 7| 1: [Parameter] b
18+
# 7| -1: [TypeMention] int
19+
# 7| 4: [IntLiteral] 42
20+
# 8| 1: [ExprStmt] ...;
21+
# 8| 0: [AssignExpr] ... = ...
22+
# 8| 0: [LocalVariableAccess] access to local variable i
23+
# 8| 1: [LambdaExpr] (...) => ...
24+
#-----| 2: (Parameters)
25+
# 8| 0: [Parameter] _
26+
# 8| 1: [Parameter] _`1
27+
# 8| 4: [IntLiteral] 42
28+
# 9| 2: [ExprStmt] ...;
29+
# 9| 0: [AssignExpr] ... = ...
30+
# 9| 0: [LocalVariableAccess] access to local variable i
31+
# 9| 1: [LambdaExpr] (...) => ...
32+
#-----| 2: (Parameters)
33+
# 9| 0: [Parameter] _
34+
# 9| -1: [TypeMention] int
35+
# 9| 1: [Parameter] _`1
36+
# 9| -1: [TypeMention] int
37+
# 9| 4: [IntLiteral] 42
38+
# 10| 3: [ExprStmt] ...;
39+
# 10| 0: [AssignExpr] ... = ...
40+
# 10| 0: [LocalVariableAccess] access to local variable i
41+
# 10| 1: [AnonymousMethodExpr] delegate(...) { ... }
42+
#-----| 2: (Parameters)
43+
# 10| 0: [Parameter] _
44+
# 10| -1: [TypeMention] int
45+
# 10| 1: [Parameter] _`1
46+
# 10| -1: [TypeMention] int
47+
# 10| 4: [BlockStmt] {...}
48+
# 10| 0: [ReturnStmt] return ...;
49+
# 10| 0: [IntLiteral] 0
150
NativeInt.cs:
2-
# 3| [Class] Class1
51+
# 3| [Class] NativeInt
352
# 5| 5: [Method] M1
453
# 5| -1: [TypeMention] Void
554
#-----| 2: (Parameters)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import csharp
22

33
from Expr e
4-
where e.fromSource()
4+
where e.getFile().getStem() = "NativeInt"
55
select e, e.getType().toString()

0 commit comments

Comments
 (0)