mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
C#: Test cases that shows that lambdas can be naturally (implicitly) typed and that the type is indistinguishable from the equivalent explicitly typed declaration.
This commit is contained in:
5
csharp/ql/test/library-tests/csharp10/lambda.expected
Normal file
5
csharp/ql/test/library-tests/csharp10/lambda.expected
Normal file
@@ -0,0 +1,5 @@
|
||||
lambdaDeclaration
|
||||
| Func<int, string> | Lambda.cs:7:27:7:28 | f1 | Lambda.cs:7:32:7:54 | (...) => ... |
|
||||
| Func<int, string> | Lambda.cs:8:13:8:14 | f2 | Lambda.cs:8:18:8:40 | (...) => ... |
|
||||
lambdaDeclarationNatural
|
||||
| Func<int, string> | Lambda.cs:8:13:8:14 | f2 | Lambda.cs:8:18:8:40 | (...) => ... |
|
||||
17
csharp/ql/test/library-tests/csharp10/lambda.ql
Normal file
17
csharp/ql/test/library-tests/csharp10/lambda.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
import csharp
|
||||
|
||||
private predicate getLambda(
|
||||
LocalVariableDeclAndInitExpr e, string type, LocalVariable v, LambdaExpr lexp
|
||||
) {
|
||||
lexp = e.getRValue() and
|
||||
v = e.getTargetVariable() and
|
||||
type = e.getType().toStringWithTypes()
|
||||
}
|
||||
|
||||
query predicate lambdaDeclaration(string type, LocalVariable v, LambdaExpr lexp) {
|
||||
getLambda(_, type, v, lexp)
|
||||
}
|
||||
|
||||
query predicate lambdaDeclarationNatural(string type, LocalVariable v, LambdaExpr lexp) {
|
||||
exists(LocalVariableDeclAndInitExpr e | getLambda(e, type, v, lexp) and e.isImplicitlyTyped())
|
||||
}
|
||||
Reference in New Issue
Block a user