Skip to content

Commit 81b03bf

Browse files
committed
C#: Add test cases for discards as lambda/delegate parameters
1 parent 7791ec3 commit 81b03bf

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
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/PrintAst.expected

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
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:
251
# 3| [Class] Class1
352
# 5| 5: [Method] M1

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
| Discard.cs:7:29:7:29 | access to local variable i | Func<Int32,Int32,Int32> |
2+
| Discard.cs:7:29:7:52 | Func<Int32,Int32,Int32> i = ... | Func<Int32,Int32,Int32> |
3+
| Discard.cs:7:33:7:52 | (...) => ... | Func<Int32,Int32,Int32> |
4+
| Discard.cs:7:51:7:52 | 42 | Int32 |
5+
| Discard.cs:8:9:8:9 | access to local variable i | Func<Int32,Int32,Int32> |
6+
| Discard.cs:8:9:8:24 | ... = ... | Func<Int32,Int32,Int32> |
7+
| Discard.cs:8:13:8:24 | (...) => ... | Func<Int32,Int32,Int32> |
8+
| Discard.cs:8:23:8:24 | 42 | Int32 |
9+
| Discard.cs:9:9:9:9 | access to local variable i | Func<Int32,Int32,Int32> |
10+
| Discard.cs:9:9:9:32 | ... = ... | Func<Int32,Int32,Int32> |
11+
| Discard.cs:9:13:9:32 | (...) => ... | Func<Int32,Int32,Int32> |
12+
| Discard.cs:9:31:9:32 | 42 | Int32 |
13+
| Discard.cs:10:9:10:9 | access to local variable i | Func<Int32,Int32,Int32> |
14+
| Discard.cs:10:9:10:49 | ... = ... | Func<Int32,Int32,Int32> |
15+
| Discard.cs:10:13:10:49 | delegate(...) { ... } | Func<Int32,Int32,Int32> |
16+
| Discard.cs:10:46:10:46 | 0 | Int32 |
117
| NativeInt.cs:7:14:7:14 | access to local variable x | IntPtr |
218
| NativeInt.cs:7:14:7:18 | IntPtr x = ... | IntPtr |
319
| NativeInt.cs:7:18:7:18 | (...) ... | IntPtr |

0 commit comments

Comments
 (0)