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

Skip to content

Commit d6feb58

Browse files
tamasvajkigfoo
authored andcommitted
Fix property references to fake overrides
1 parent 4eb1e3a commit d6feb58

4 files changed

Lines changed: 89 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ open class KotlinFileExtractor(
27712771

27722772
writeExpressionMetadataToTrapFile(callId, labels.methodId, retId)
27732773

2774-
val callableId = useFunction<DbCallable>(target.owner, classTypeArgsIncludingOuterClasses)
2774+
val callableId = useFunction<DbCallable>(target.owner.realOverrideTarget, classTypeArgsIncludingOuterClasses)
27752775
@Suppress("UNCHECKED_CAST")
27762776
tw.writeCallableBinding(callId as Label<out DbCaller>, callableId)
27772777

@@ -2897,7 +2897,7 @@ open class KotlinFileExtractor(
28972897
if (getter != null) {
28982898
val getterParameterTypes = parameterTypes.dropLast(1)
28992899
val getLabels = addFunctionManual(tw.getFreshIdLabel(), "get", getterParameterTypes, parameterTypes.last(), classId, locId)
2900-
val getterCallableId = useFunction<DbCallable>(getter.owner, classTypeArguments)
2900+
val getterCallableId = useFunction<DbCallable>(getter.owner.realOverrideTarget, classTypeArguments)
29012901

29022902
helper.extractCallToReflectionTarget(
29032903
getLabels,
@@ -2929,7 +2929,7 @@ open class KotlinFileExtractor(
29292929
if (setter != null) {
29302930
val setLabels = addFunctionManual(tw.getFreshIdLabel(), "set", parameterTypes, pluginContext.irBuiltIns.unitType, classId, locId)
29312931

2932-
val setterCallableId = useFunction<DbCallable>(setter.owner, classTypeArguments)
2932+
val setterCallableId = useFunction<DbCallable>(setter.owner.realOverrideTarget, classTypeArguments)
29332933

29342934
helper.extractCallToReflectionTarget(
29352935
setLabels,
@@ -3043,7 +3043,7 @@ open class KotlinFileExtractor(
30433043
dispatchReceiverIdx = -1
30443044
}
30453045

3046-
val targetCallableId = useFunction<DbCallable>(target.owner, classTypeArguments)
3046+
val targetCallableId = useFunction<DbCallable>(target.owner.realOverrideTarget, classTypeArguments)
30473047
val locId = tw.getLocation(functionReferenceExpr)
30483048

30493049
val javaResult = TypeResult(tw.getFreshIdLabel<DbClass>(), "", "")

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,3 +915,74 @@ reflection.kt:
915915
# 90| 1: [TypeAccess] Inner<String>
916916
# 90| 0: [TypeAccess] String
917917
# 90| 0: [ThisAccess] this
918+
# 105| 8: [Class] Base1
919+
# 105| 1: [Constructor] Base1
920+
#-----| 4: (Parameters)
921+
# 105| 0: [Parameter] prop1
922+
# 105| 5: [BlockStmt] { ... }
923+
# 105| 0: [SuperConstructorInvocationStmt] super(...)
924+
# 105| 1: [BlockStmt] { ... }
925+
# 105| 0: [ExprStmt] <Expr>;
926+
# 105| 0: [KtInitializerAssignExpr] ...=...
927+
# 105| 0: [VarAccess] prop1
928+
# 105| 2: [Method] getProp1
929+
# 105| 5: [BlockStmt] { ... }
930+
# 105| 0: [ReturnStmt] return ...
931+
# 105| 0: [VarAccess] this.prop1
932+
# 105| -1: [ThisAccess] this
933+
# 105| 2: [Method] setProp1
934+
#-----| 4: (Parameters)
935+
# 105| 0: [Parameter] <set-?>
936+
# 105| 5: [BlockStmt] { ... }
937+
# 105| 0: [ExprStmt] <Expr>;
938+
# 105| 0: [AssignExpr] ...=...
939+
# 105| 0: [VarAccess] this.prop1
940+
# 105| -1: [ThisAccess] this
941+
# 105| 1: [VarAccess] <set-?>
942+
# 105| 2: [FieldDeclaration] int prop1;
943+
# 105| -1: [TypeAccess] int
944+
# 105| 0: [VarAccess] prop1
945+
# 107| 9: [Class] Derived1
946+
# 107| 1: [Constructor] Derived1
947+
#-----| 4: (Parameters)
948+
# 107| 0: [Parameter] prop1
949+
# 107| 5: [BlockStmt] { ... }
950+
# 107| 0: [SuperConstructorInvocationStmt] super(...)
951+
# 107| 0: [VarAccess] prop1
952+
# 108| 2: [Method] fn
953+
# 108| 5: [BlockStmt] { ... }
954+
# 109| 0: [ExprStmt] <Expr>;
955+
# 109| 0: [MethodAccess] println(...)
956+
# 109| -1: [TypeAccess] ConsoleKt
957+
# 109| 0: [PropertyRefExpr] ...::...
958+
# 109| -4: [AnonymousClass] new KMutableProperty0<Integer>(...) { ... }
959+
# 109| 1: [Constructor]
960+
#-----| 4: (Parameters)
961+
# 109| 0: [Parameter] <dispatchReceiver>
962+
# 109| 5: [BlockStmt] { ... }
963+
# 109| 0: [SuperConstructorInvocationStmt] super(...)
964+
# 109| 1: [ExprStmt] <Expr>;
965+
# 109| 0: [AssignExpr] ...=...
966+
# 109| 0: [VarAccess] this.<dispatchReceiver>
967+
# 109| -1: [ThisAccess] this
968+
# 109| 1: [VarAccess] <dispatchReceiver>
969+
# 109| 1: [FieldDeclaration] Derived1 <dispatchReceiver>;
970+
# 109| -1: [TypeAccess] Derived1
971+
# 109| 1: [Method] get
972+
# 109| 5: [BlockStmt] { ... }
973+
# 109| 0: [ReturnStmt] return ...
974+
# 109| 0: [MethodAccess] getProp1(...)
975+
# 109| -1: [VarAccess] this.<dispatchReceiver>
976+
# 109| -1: [ThisAccess] this
977+
# 109| 1: [Method] set
978+
#-----| 4: (Parameters)
979+
# 109| 0: [Parameter] a0
980+
# 109| 5: [BlockStmt] { ... }
981+
# 109| 0: [ReturnStmt] return ...
982+
# 109| 0: [MethodAccess] setProp1(...)
983+
# 109| -1: [VarAccess] this.<dispatchReceiver>
984+
# 109| -1: [ThisAccess] this
985+
# 109| 0: [VarAccess] a0
986+
# 109| -3: [TypeAccess] KMutableProperty0<Integer>
987+
# 109| 0: [TypeAccess] Integer
988+
# 109| 0: [ThisAccess] this

java/ql/test/kotlin/library-tests/reflection/reflection.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ propertyGetReferences
5858
| reflection.kt:67:17:67:32 | ...::... | reflection.kt:67:17:67:32 | get | reflection.kt:78:13:78:24 | getP2 |
5959
| reflection.kt:68:17:68:34 | ...::... | reflection.kt:68:17:68:34 | get | reflection.kt:78:13:78:24 | getP2 |
6060
| reflection.kt:70:17:70:30 | ...::... | reflection.kt:70:17:70:30 | get | file://<external>/IntCompanionObject.class:0:0:0:0 | getMAX_VALUE |
61+
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | get | reflection.kt:105:18:105:31 | getProp1 |
6162
propertyFieldReferences
6263
| reflection.kt:71:17:71:34 | ...::... | reflection.kt:71:17:71:34 | get | file:///modules/java.base/java/lang/Integer.class:0:0:0:0 | MAX_VALUE |
6364
| reflection.kt:72:17:72:35 | ...::... | reflection.kt:72:17:72:35 | get | file:///modules/java.desktop/java/awt/Rectangle.class:0:0:0:0 | height |
@@ -66,6 +67,7 @@ propertySetReferences
6667
| reflection.kt:22:42:22:48 | ...::... | reflection.kt:22:42:22:48 | set | reflection.kt:34:9:34:23 | setP1 |
6768
| reflection.kt:67:17:67:32 | ...::... | reflection.kt:67:17:67:32 | set | reflection.kt:79:13:79:29 | setP2 |
6869
| reflection.kt:68:17:68:34 | ...::... | reflection.kt:68:17:68:34 | set | reflection.kt:79:13:79:29 | setP2 |
70+
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | set | reflection.kt:105:18:105:31 | setProp1 |
6971
callsInsideInvocationMethods
7072
| reflection.kt:7:49:7:54 | ...::... | reflection.kt:7:49:7:54 | new Function2<Ccc,Integer,Double>(...) { ... } | reflection.kt:7:49:7:54 | invoke | reflection.kt:7:49:7:54 | m(...) | Ccc.m |
7173
| reflection.kt:10:38:10:42 | ...::... | reflection.kt:10:38:10:42 | new KProperty1<C,Integer>(...) { ... } | reflection.kt:10:38:10:42 | get | reflection.kt:10:38:10:42 | getP0(...) | C.getP0 |
@@ -93,6 +95,8 @@ callsInsideInvocationMethods
9395
| reflection.kt:97:14:97:21 | ...::... | reflection.kt:97:14:97:21 | new Function1<String,Class2<String>>(...) { ... } | reflection.kt:97:14:97:21 | invoke | reflection.kt:97:14:97:21 | new Class2<String>(...) | Class2<String>.Class2<String> |
9496
| reflection.kt:98:14:98:17 | ...::... | reflection.kt:98:14:98:17 | new Function1<String,Unit>(...) { ... } | reflection.kt:98:14:98:17 | invoke | reflection.kt:98:14:98:17 | fn(...) | ReflectionKt.fn |
9597
| reflection.kt:99:14:99:29 | ...::... | reflection.kt:99:14:99:29 | new Function1<String,Inner<String>>(...) { ... } | reflection.kt:99:14:99:29 | invoke | reflection.kt:99:14:99:29 | new Inner<String>(...) | Inner<String>.Inner<String> |
98+
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | new KMutableProperty0<Integer>(...) { ... } | reflection.kt:109:17:109:27 | get | reflection.kt:109:17:109:27 | getProp1(...) | Base1.getProp1 |
99+
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | new KMutableProperty0<Integer>(...) { ... } | reflection.kt:109:17:109:27 | set | reflection.kt:109:17:109:27 | setProp1(...) | Base1.setProp1 |
96100
fieldAccessInsideInvocationMethods
97101
| reflection.kt:14:38:14:44 | ...::... | reflection.kt:14:38:14:44 | new Function1<C,Integer>(...) { ... } | reflection.kt:14:38:14:44 | invoke | reflection.kt:14:38:14:44 | this.<dispatchReceiver> |
98102
| reflection.kt:15:35:15:41 | ...::... | reflection.kt:15:35:15:41 | new KProperty0<Integer>(...) { ... } | reflection.kt:15:35:15:41 | get | reflection.kt:15:35:15:41 | this.<dispatchReceiver> |
@@ -113,3 +117,5 @@ fieldAccessInsideInvocationMethods
113117
| reflection.kt:72:17:72:35 | ...::... | reflection.kt:72:17:72:35 | new KMutableProperty0<Integer>(...) { ... } | reflection.kt:72:17:72:35 | set | reflection.kt:72:17:72:35 | this.<dispatchReceiver>.height |
114118
| reflection.kt:90:18:90:24 | ...::... | reflection.kt:90:18:90:24 | new Function1<String,Inner<String>>(...) { ... } | reflection.kt:90:18:90:24 | invoke | reflection.kt:90:18:90:24 | this.<dispatchReceiver> |
115119
| reflection.kt:99:14:99:29 | ...::... | reflection.kt:99:14:99:29 | new Function1<String,Inner<String>>(...) { ... } | reflection.kt:99:14:99:29 | invoke | reflection.kt:99:14:99:29 | this.<dispatchReceiver> |
120+
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | new KMutableProperty0<Integer>(...) { ... } | reflection.kt:109:17:109:27 | get | reflection.kt:109:17:109:27 | this.<dispatchReceiver> |
121+
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | new KMutableProperty0<Integer>(...) { ... } | reflection.kt:109:17:109:27 | set | reflection.kt:109:17:109:27 | this.<dispatchReceiver> |

java/ql/test/kotlin/library-tests/reflection/reflection.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ fun test() {
101101

102102
fun <T, R> fn11(l: T, transform: (T) -> R) { }
103103
fun <T1, R> fn12(l: T1, l2: (T1) -> R) { }
104+
105+
open class Base1(var prop1: Int) {}
106+
107+
class Derived1(prop1: Int) : Base1(prop1) {
108+
fun fn() {
109+
println(this::prop1)
110+
}
111+
}

0 commit comments

Comments
 (0)