Visitar URL original
C#: C#9 add test cases for discards as lambda/delegate parameters by tamasvajk · Pull Request #4613 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20260603084303/https://github.com/github/codeql/pull/4613/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions csharp/ql/test/library-tests/csharp9/Discard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

public class Discard
{
public void M1()
{
Func<int, int, int> i = (int a, int b) => 42;
i = (_, _) => 42;
i = (int _, int _) => 42;
i = delegate (int _, int _) { return 0; };
}
}
8 changes: 8 additions & 0 deletions csharp/ql/test/library-tests/csharp9/Discard.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| Discard.cs:7:33:7:52 | (...) => ... | Discard.cs:7:38:7:38 | a |
| Discard.cs:7:33:7:52 | (...) => ... | Discard.cs:7:45:7:45 | b |
| Discard.cs:8:13:8:24 | (...) => ... | Discard.cs:8:14:8:14 | _ |
| Discard.cs:8:13:8:24 | (...) => ... | Discard.cs:8:17:8:17 | _`1 |
| Discard.cs:9:13:9:32 | (...) => ... | Discard.cs:9:18:9:18 | _ |
| Discard.cs:9:13:9:32 | (...) => ... | Discard.cs:9:25:9:25 | _`1 |
| Discard.cs:10:13:10:49 | delegate(...) { ... } | Discard.cs:10:27:10:27 | _ |
| Discard.cs:10:13:10:49 | delegate(...) { ... } | Discard.cs:10:34:10:34 | _`1 |
4 changes: 4 additions & 0 deletions csharp/ql/test/library-tests/csharp9/Discard.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import csharp

from AnonymousFunctionExpr anon
select anon, anon.getAParameter()
2 changes: 1 addition & 1 deletion csharp/ql/test/library-tests/csharp9/NativeInt.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

public class Class1
public class NativeInt
{
public void M1(int j, uint k)
{
Expand Down
51 changes: 50 additions & 1 deletion csharp/ql/test/library-tests/csharp9/PrintAst.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
Discard.cs:
# 3| [Class] Discard
# 5| 5: [Method] M1
# 5| -1: [TypeMention] Void
# 6| 4: [BlockStmt] {...}
# 7| 0: [LocalVariableDeclStmt] ... ...;
# 7| 0: [LocalVariableDeclAndInitExpr] Func<Int32,Int32,Int32> i = ...
# 7| -1: [TypeMention] Func<Int32, Int32, Int32>
# 7| 1: [TypeMention] int
# 7| 2: [TypeMention] int
# 7| 3: [TypeMention] int
# 7| 0: [LocalVariableAccess] access to local variable i
# 7| 1: [LambdaExpr] (...) => ...
#-----| 2: (Parameters)
# 7| 0: [Parameter] a
# 7| -1: [TypeMention] int
# 7| 1: [Parameter] b
# 7| -1: [TypeMention] int
# 7| 4: [IntLiteral] 42
# 8| 1: [ExprStmt] ...;
# 8| 0: [AssignExpr] ... = ...
# 8| 0: [LocalVariableAccess] access to local variable i
# 8| 1: [LambdaExpr] (...) => ...
#-----| 2: (Parameters)
# 8| 0: [Parameter] _
# 8| 1: [Parameter] _`1
# 8| 4: [IntLiteral] 42
# 9| 2: [ExprStmt] ...;
# 9| 0: [AssignExpr] ... = ...
# 9| 0: [LocalVariableAccess] access to local variable i
# 9| 1: [LambdaExpr] (...) => ...
#-----| 2: (Parameters)
# 9| 0: [Parameter] _
# 9| -1: [TypeMention] int
# 9| 1: [Parameter] _`1
# 9| -1: [TypeMention] int
# 9| 4: [IntLiteral] 42
# 10| 3: [ExprStmt] ...;
# 10| 0: [AssignExpr] ... = ...
# 10| 0: [LocalVariableAccess] access to local variable i
# 10| 1: [AnonymousMethodExpr] delegate(...) { ... }
#-----| 2: (Parameters)
# 10| 0: [Parameter] _
# 10| -1: [TypeMention] int
# 10| 1: [Parameter] _`1
# 10| -1: [TypeMention] int
# 10| 4: [BlockStmt] {...}
# 10| 0: [ReturnStmt] return ...;
# 10| 0: [IntLiteral] 0
NativeInt.cs:
# 3| [Class] Class1
# 3| [Class] NativeInt
# 5| 5: [Method] M1
# 5| -1: [TypeMention] Void
#-----| 2: (Parameters)
Expand Down
2 changes: 1 addition & 1 deletion csharp/ql/test/library-tests/csharp9/nativeInt.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import csharp

from Expr e
where e.fromSource()
where e.getFile().getStem() = "NativeInt"
select e, e.getType().toString()