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

Skip to content

Commit 4e18974

Browse files
tamasvajkigfoo
authored andcommitted
Fix type access expression extraction for function/property references
1 parent 73c5f8c commit 4e18974

5 files changed

Lines changed: 133 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,10 @@ open class KotlinFileExtractor(
16871687
) {
16881688
typeArgs.forEachIndexed { argIdx, arg ->
16891689
val mul = if (reverse) -1 else 1
1690-
extractTypeAccess(arg, enclosingCallable, parentExpr, argIdx * mul + startIndex, elementForLocation, enclosingStmt, TypeContext.GENERIC_ARGUMENT)
1690+
val ta = extractTypeAccess(arg, enclosingCallable, parentExpr, argIdx * mul + startIndex, elementForLocation, enclosingStmt, TypeContext.GENERIC_ARGUMENT)
1691+
if (arg is IrSimpleType) {
1692+
extractTypeArguments(arg.arguments.filterIsInstance<IrType>(), elementForLocation, ta, enclosingCallable, enclosingStmt)
1693+
}
16911694
}
16921695
}
16931696

@@ -2829,7 +2832,8 @@ open class KotlinFileExtractor(
28292832
tw.writeStatementEnclosingExpr(idPropertyRef, exprParent.enclosingStmt)
28302833
tw.writeCallableBinding(idPropertyRef, ids.constructor)
28312834

2832-
extractTypeAccess(kPropertyType, locId, callable, idPropertyRef, -3, exprParent.enclosingStmt)
2835+
val typeAccessId = extractTypeAccess(kPropertyType, locId, callable, idPropertyRef, -3, exprParent.enclosingStmt)
2836+
extractTypeArguments(parameterTypes, propertyReferenceExpr, typeAccessId, callable, exprParent.enclosingStmt)
28332837

28342838
helper.extractConstructorArguments(callable, idPropertyRef, exprParent.enclosingStmt)
28352839

@@ -2972,7 +2976,9 @@ open class KotlinFileExtractor(
29722976
tw.writeStatementEnclosingExpr(idMemberRef, exprParent.enclosingStmt)
29732977
tw.writeCallableBinding(idMemberRef, ids.constructor)
29742978

2975-
extractTypeAccess(fnInterfaceType, locId, callable, idMemberRef, -3, exprParent.enclosingStmt)
2979+
val typeAccessId = extractTypeAccess(fnInterfaceType, locId, callable, idMemberRef, -3, exprParent.enclosingStmt)
2980+
val typeAccessArguments = if (isBigArity) listOf(parameterTypes.last()) else parameterTypes
2981+
extractTypeArguments(typeAccessArguments, functionReferenceExpr, typeAccessId, callable, exprParent.enclosingStmt)
29762982

29772983
tw.writeMemberRefBinding(idMemberRef, targetCallableId)
29782984

@@ -3497,6 +3503,7 @@ open class KotlinFileExtractor(
34973503
tw.writeIsAnonymClass(ids.type.javaResult.id as Label<DbClass>, idNewexpr)
34983504

34993505
extractTypeAccess(e.typeOperand, callable, idNewexpr, -3, e, enclosingStmt)
3506+
35003507
extractExpressionExpr(e.argument, callable, idNewexpr, 0, enclosingStmt)
35013508
}
35023509
else -> {

java/ql/test/kotlin/library-tests/classes/PrintAst.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ local_anonymous.kt:
475475
# 21| 0: [MethodAccess] fn3(...)
476476
# 21| -1: [VarAccess] a0
477477
# 21| -3: [TypeAccess] Function1<Class1,Unit>
478+
# 21| 0: [TypeAccess] Class1
479+
# 21| 1: [TypeAccess] Unit
478480
# 24| 6: [Method] fn5
479481
# 24| 5: [BlockStmt] { ... }
480482
# 25| 0: [LocalTypeDeclStmt] class ...

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,7 @@ funcExprs.kt:
15481548
# 32| 1: [FieldDeclaration] FuncRef <dispatchReceiver>;
15491549
# 32| -1: [TypeAccess] FuncRef
15501550
# 32| -3: [TypeAccess] Function0<Integer>
1551+
# 32| 0: [TypeAccess] Integer
15511552
# 32| 0: [ClassInstanceExpr] new FuncRef(...)
15521553
# 32| -3: [TypeAccess] FuncRef
15531554
# 33| 15: [ExprStmt] <Expr>;
@@ -1573,6 +1574,7 @@ funcExprs.kt:
15731574
# 33| 1: [FieldDeclaration] Companion <dispatchReceiver>;
15741575
# 33| -1: [TypeAccess] Companion
15751576
# 33| -3: [TypeAccess] Function0<Integer>
1577+
# 33| 0: [TypeAccess] Integer
15761578
# 33| 0: [VarAccess] Companion
15771579
# 34| 16: [ExprStmt] <Expr>;
15781580
# 34| 0: [MethodAccess] functionExpression1a(...)
@@ -1601,6 +1603,8 @@ funcExprs.kt:
16011603
# 34| 1: [FieldDeclaration] FuncRef <dispatchReceiver>;
16021604
# 34| -1: [TypeAccess] FuncRef
16031605
# 34| -3: [TypeAccess] Function1<Integer,Integer>
1606+
# 34| 0: [TypeAccess] Integer
1607+
# 34| 1: [TypeAccess] Integer
16041608
# 34| 0: [ClassInstanceExpr] new FuncRef(...)
16051609
# 34| -3: [TypeAccess] FuncRef
16061610
# 35| 17: [ExprStmt] <Expr>;
@@ -1621,6 +1625,9 @@ funcExprs.kt:
16211625
# 35| -1: [VarAccess] a0
16221626
# 35| 0: [VarAccess] a1
16231627
# 35| -3: [TypeAccess] Function2<FuncRef,Integer,Integer>
1628+
# 35| 0: [TypeAccess] FuncRef
1629+
# 35| 1: [TypeAccess] Integer
1630+
# 35| 2: [TypeAccess] Integer
16241631
# 36| 18: [ExprStmt] <Expr>;
16251632
# 36| 0: [MethodAccess] functionExpression1a(...)
16261633
# 36| 0: [IntegerLiteral] 5
@@ -1648,6 +1655,8 @@ funcExprs.kt:
16481655
# 36| 1: [FieldDeclaration] int <extensionReceiver>;
16491656
# 36| -1: [TypeAccess] int
16501657
# 36| -3: [TypeAccess] Function1<Integer,Integer>
1658+
# 36| 0: [TypeAccess] Integer
1659+
# 36| 1: [TypeAccess] Integer
16511660
# 36| 0: [IntegerLiteral] 3
16521661
# 37| 19: [ExprStmt] <Expr>;
16531662
# 37| 0: [MethodAccess] functionExpression3(...)
@@ -1667,6 +1676,9 @@ funcExprs.kt:
16671676
# 37| 0: [VarAccess] a0
16681677
# 37| 1: [VarAccess] a1
16691678
# 37| -3: [TypeAccess] Function2<Integer,Integer,Integer>
1679+
# 37| 0: [TypeAccess] Integer
1680+
# 37| 1: [TypeAccess] Integer
1681+
# 37| 2: [TypeAccess] Integer
16701682
# 38| 20: [ExprStmt] <Expr>;
16711683
# 38| 0: [MethodAccess] functionExpression22(...)
16721684
# 38| 0: [IntegerLiteral] 5
@@ -1736,6 +1748,29 @@ funcExprs.kt:
17361748
# 38| 1: [FieldDeclaration] FuncRef <dispatchReceiver>;
17371749
# 38| -1: [TypeAccess] FuncRef
17381750
# 38| -3: [TypeAccess] Function22<Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Integer,Unit>
1751+
# 38| 0: [TypeAccess] Integer
1752+
# 38| 1: [TypeAccess] Integer
1753+
# 38| 2: [TypeAccess] Integer
1754+
# 38| 3: [TypeAccess] Integer
1755+
# 38| 4: [TypeAccess] Integer
1756+
# 38| 5: [TypeAccess] Integer
1757+
# 38| 6: [TypeAccess] Integer
1758+
# 38| 7: [TypeAccess] Integer
1759+
# 38| 8: [TypeAccess] Integer
1760+
# 38| 9: [TypeAccess] Integer
1761+
# 38| 10: [TypeAccess] Integer
1762+
# 38| 11: [TypeAccess] Integer
1763+
# 38| 12: [TypeAccess] Integer
1764+
# 38| 13: [TypeAccess] Integer
1765+
# 38| 14: [TypeAccess] Integer
1766+
# 38| 15: [TypeAccess] Integer
1767+
# 38| 16: [TypeAccess] Integer
1768+
# 38| 17: [TypeAccess] Integer
1769+
# 38| 18: [TypeAccess] Integer
1770+
# 38| 19: [TypeAccess] Integer
1771+
# 38| 20: [TypeAccess] Integer
1772+
# 38| 21: [TypeAccess] Integer
1773+
# 38| 22: [TypeAccess] Unit
17391774
# 38| 0: [ClassInstanceExpr] new FuncRef(...)
17401775
# 38| -3: [TypeAccess] FuncRef
17411776
# 39| 21: [ExprStmt] <Expr>;
@@ -1879,6 +1914,7 @@ funcExprs.kt:
18791914
# 39| 1: [FieldDeclaration] FuncRef <dispatchReceiver>;
18801915
# 39| -1: [TypeAccess] FuncRef
18811916
# 39| -3: [TypeAccess] FunctionN<String>
1917+
# 39| 0: [TypeAccess] String
18821918
# 39| 0: [ClassInstanceExpr] new FuncRef(...)
18831919
# 39| -3: [TypeAccess] FuncRef
18841920
# 40| 22: [ExprStmt] <Expr>;
@@ -2016,6 +2052,7 @@ funcExprs.kt:
20162052
# 40| -1: [VarAccess] a0
20172053
# 40| 23: [IntegerLiteral] 23
20182054
# 40| -3: [TypeAccess] FunctionN<String>
2055+
# 40| 0: [TypeAccess] String
20192056
# 42| 23: [LocalTypeDeclStmt] class ...
20202057
# 42| 0: [LocalClass]
20212058
# 42| 1: [Constructor]
@@ -2037,6 +2074,7 @@ funcExprs.kt:
20372074
# 43| 0: [ReturnStmt] return ...
20382075
# 43| 0: [MethodAccess] local(...)
20392076
# 43| -3: [TypeAccess] Function0<Integer>
2077+
# 43| 0: [TypeAccess] Integer
20402078
# 45| 25: [ExprStmt] <Expr>;
20412079
# 45| 0: [MethodAccess] fn(...)
20422080
# 45| -2: [TypeAccess] FuncRef
@@ -2051,6 +2089,7 @@ funcExprs.kt:
20512089
# 45| 0: [ClassInstanceExpr] new FuncRef(...)
20522090
# 45| -3: [TypeAccess] FuncRef
20532091
# 45| -3: [TypeAccess] Function0<FuncRef>
2092+
# 45| 0: [TypeAccess] FuncRef
20542093
# 52| 14: [Method] fn
20552094
#-----| 2: (Generic Parameters)
20562095
# 52| 0: [TypeVariable] T
@@ -2355,6 +2394,9 @@ samConversion.kt:
23552394
# 5| 0: [VarAccess] a0
23562395
# 5| 1: [VarAccess] a1
23572396
# 5| -3: [TypeAccess] Function2<Integer,Integer,Unit>
2397+
# 5| 0: [TypeAccess] Integer
2398+
# 5| 1: [TypeAccess] Integer
2399+
# 5| 2: [TypeAccess] Unit
23582400
# 7| 3: [LocalVariableDeclStmt] var ...;
23592401
# 7| 1: [LocalVariableDeclExpr] i
23602402
# 7| 0: [CastExpr] (...)...
@@ -2631,6 +2673,7 @@ samConversion.kt:
26312673
# 41| -1: [VarAccess] a0
26322674
# 41| 22: [IntegerLiteral] 22
26332675
# 41| -3: [TypeAccess] FunctionN<Boolean>
2676+
# 41| 0: [TypeAccess] Boolean
26342677
# 42| 1: [LocalVariableDeclStmt] var ...;
26352678
# 42| 1: [LocalVariableDeclExpr] b
26362679
# 42| 0: [CastExpr] (...)...

0 commit comments

Comments
 (0)