Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b58d01

Browse files
tamasvajkigfoo
authored andcommitted
Specify lambda method for big arity lambdas
1 parent dec165c commit 7b58d01

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,6 @@ open class KotlinFileExtractor(
16771677

16781678
if (types.size > BuiltInFunctionArity.BIG_ARITY) {
16791679
implementFunctionNInvoke(e.function, ids, locId, parameters)
1680-
1681-
// todo: which method should be returned in `LambdaExpr.asMethod()`?
16821680
}
16831681

16841682
val exprParent = parent.expr(e, callable)

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,21 @@ class LambdaExpr extends FunctionalExpr, @lambdaexpr {
12561256
* Gets the implicit method corresponding to this lambda expression.
12571257
* The parameters of the lambda expression are the parameters of this method.
12581258
*/
1259-
override Method asMethod() { result = this.getAnonymousClass().getAMethod() }
1259+
override Method asMethod() {
1260+
not isKotlinFunctionN() and
1261+
result = this.getAnonymousClass().getAMethod()
1262+
or
1263+
isKotlinFunctionN() and
1264+
result = this.getAnonymousClass().getAMethod() and
1265+
result.getNumberOfParameters() = 1
1266+
}
1267+
1268+
predicate isKotlinFunctionN() {
1269+
exists(RefType r |
1270+
this.getAnonymousClass().extendsOrImplements(r) and
1271+
r.getSourceDeclaration().hasQualifiedName("kotlin.jvm.functions", "FunctionN")
1272+
)
1273+
}
12601274

12611275
/** Holds if the body of this lambda is an expression. */
12621276
predicate hasExprBody() { lambdaKind(this, 0) }
@@ -2202,9 +2216,7 @@ class WhenBranch extends Top, @whenbranch {
22022216
predicate isElseBranch() { when_branch_else(this) }
22032217

22042218
/** Gets the `when` expression this is a branch of. */
2205-
WhenExpr getWhenExpr() {
2206-
this = result.getBranch(_)
2207-
}
2219+
WhenExpr getWhenExpr() { this = result.getBranch(_) }
22082220

22092221
override string toString() { result = "... -> ..." }
22102222

java/ql/test/kotlin/library-tests/exprs/funcExprs.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
| funcExprs.kt:25:28:25:51 | ...->... | stmt body | funcExprs.kt:25:28:25:51 | invoke | invoke(int) | funcExprs.kt:25:28:25:51 | new Function1<Integer,Function1<Integer,Double>>(...) { ... } |
1212
| funcExprs.kt:25:37:25:47 | ...->... | stmt body | funcExprs.kt:25:37:25:47 | invoke | invoke(int) | funcExprs.kt:25:37:25:47 | new Function1<Integer,Double>(...) { ... } |
1313
| funcExprs.kt:27:29:27:112 | ...->... | stmt body | funcExprs.kt:27:29:27:112 | invoke | invoke(int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int) | funcExprs.kt:27:29:27:112 | new Function22<Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Unit>(...) { ... } |
14-
| funcExprs.kt:28:29:28:117 | ...->... | stmt body | funcExprs.kt:28:29:28:117 | invoke | invoke(int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int) | funcExprs.kt:28:29:28:117 | new FunctionN<String>(...) { ... } |
1514
| funcExprs.kt:28:29:28:117 | ...->... | stmt body | funcExprs.kt:28:29:28:117 | invoke | invoke(java.lang.Object[]) | funcExprs.kt:28:29:28:117 | new FunctionN<String>(...) { ... } |

0 commit comments

Comments
 (0)