Recognize qualified this access of outer class instance

This commit is contained in:
Tamas Vajk
2021-09-23 10:52:37 +02:00
committed by Ian Lynagh
parent 3bfc93daab
commit d6ec230e2f
4 changed files with 42 additions and 5 deletions

View File

@@ -413,19 +413,31 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
@Suppress("UNCHECKED_CAST")
val parentId: Label<out DbMethod> = useDeclarationParent(vp.parent) as Label<out DbMethod>
var idx = vp.index
if (isQualifiedThis(vp)) {
if (isQualifiedThisFunction(vp)) {
idx = -2
}
val label = "@\"params;{$parentId};$idx\""
return label
}
private fun isQualifiedThis(vp: IrValueParameter) : Boolean {
private fun isQualifiedThis(vp: IrValueParameter): Boolean {
return isQualifiedThisFunction(vp) ||
isQualifiedThisClass(vp)
}
private fun isQualifiedThisFunction(vp: IrValueParameter): Boolean {
val parent = vp.parent
return vp.index == -1 &&
parent is IrFunction &&
parent.dispatchReceiverParameter == vp &&
parent.extensionReceiverParameter != null
parent is IrFunction &&
parent.dispatchReceiverParameter == vp &&
parent.extensionReceiverParameter != null
}
private fun isQualifiedThisClass(vp: IrValueParameter): Boolean {
val parent = vp.parent
return vp.index == -1 &&
parent is IrClass &&
parent.thisReceiver == vp
}
fun useValueParameter(vp: IrValueParameter): Label<out DbParam> {

View File

@@ -8,4 +8,6 @@ instAcc
| variables.kt:28:9:28:12 | this |
| variables.kt:31:9:31:15 | this |
| variables.kt:32:9:32:15 | this |
| variables.kt:41:13:41:16 | this |
| variables.kt:42:13:42:19 | this |
instAccQualifier

View File

@@ -24,3 +24,15 @@
| variables.kt:20:5:22:5 | <this> | variables.kt:16:1:34:1 | C2 | file://:0:0:0:0 | <none> |
| variables.kt:23:5:33:5 | <this> | variables.kt:16:1:34:1 | C2 | file://:0:0:0:0 | <none> |
| variables.kt:23:9:23:10 | <this> | variables.kt:12:1:15:1 | C1 | file://:0:0:0:0 | <none> |
| variables.kt:36:1:45:1 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:36:1:45:1 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:36:1:45:1 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:36:1:45:1 | other | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:37:5:37:15 | <this> | variables.kt:36:1:45:1 | C3 | file://:0:0:0:0 | <none> |
| variables.kt:38:5:44:5 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:38:5:44:5 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:38:5:44:5 | <this> | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:38:5:44:5 | <this> | variables.kt:36:1:45:1 | C3 | file://:0:0:0:0 | <none> |
| variables.kt:38:11:44:5 | other | file://:0:0:0:0 | Any | file://:0:0:0:0 | <none> |
| variables.kt:39:9:39:19 | <this> | variables.kt:38:5:44:5 | C4 | file://:0:0:0:0 | <none> |
| variables.kt:40:9:43:9 | <this> | variables.kt:38:5:44:5 | C4 | file://:0:0:0:0 | <none> |

View File

@@ -31,4 +31,15 @@ class C2 (val o:C1) {
this@C2.f1() // dispatchReceiverParameter
this@C2.f3() // dispatchReceiverParameter
}
}
class C3 {
fun f0() {}
inner class C4 {
fun f0() {}
fun f1() {
this.f0()
this@C3.f0()
}
}
}