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:
Michael Nebel
2022-01-26 09:43:49 +01:00
parent a67033034a
commit ccb727e3ca
2 changed files with 22 additions and 0 deletions

View 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 | (...) => ... |

View 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())
}