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

Skip to content

Commit 616f20f

Browse files
tamasvajkigfoo
authored andcommitted
Handle more cases of qualified this references
1 parent 7fe260c commit 616f20f

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,17 +1934,27 @@ open class KotlinFileExtractor(
19341934
tw.writeCallableEnclosingExpr(id, callable)
19351935
tw.writeStatementEnclosingExpr(id, exprParent.enclosingStmt)
19361936

1937+
1938+
fun extractTypeAccess(parent: IrClass){
1939+
extractTypeAccess(parent.typeWith(listOf()), locId, callable, id, 0, exprParent.enclosingStmt)
1940+
}
1941+
19371942
when(val ownerParent = owner.parent) {
19381943
is IrFunction -> {
19391944
if (ownerParent.dispatchReceiverParameter == owner &&
19401945
ownerParent.extensionReceiverParameter != null) {
1941-
logger.errorElement("Function-qualifier for this", e)
1946+
1947+
val ownerParent2 = ownerParent.parent
1948+
if (ownerParent2 is IrClass){
1949+
extractTypeAccess(ownerParent2)
1950+
} else {
1951+
logger.errorElement("Unhandled qualifier for this", e)
1952+
}
19421953
}
19431954
}
19441955
is IrClass -> {
19451956
if (ownerParent.thisReceiver == owner) {
1946-
// TODO: Type arguments
1947-
extractTypeAccess(ownerParent.typeWith(listOf()), locId, callable, id, 0, exprParent.enclosingStmt)
1957+
extractTypeAccess(ownerParent)
19481958
}
19491959
}
19501960
else -> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| this.kt:20:42:20:45 | this | file://:0:0:0:0 | <none> |
1010
| this.kt:24:34:24:37 | this | file://:0:0:0:0 | <none> |
1111
| this.kt:29:38:29:41 | this | file://:0:0:0:0 | <none> |
12-
| this.kt:30:29:30:38 | this | file://:0:0:0:0 | <none> |
12+
| this.kt:30:29:30:38 | Inner.this | this.kt:30:29:30:38 | Inner |
1313
| this.kt:31:29:31:38 | Outer.this | this.kt:31:29:31:38 | Outer |
1414
| this.kt:32:38:32:54 | this | file://:0:0:0:0 | <none> |
1515
| this.kt:37:13:37:22 | Outer.this | this.kt:37:13:37:22 | Outer |

java/ql/test/kotlin/library-tests/variables/variableAccesses.expected

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ instAcc
1010
| variables.kt:21:11:21:15 | this |
1111
| variables.kt:24:9:24:9 | this |
1212
| variables.kt:25:9:25:9 | this |
13-
| variables.kt:26:9:26:12 | this |
13+
| variables.kt:26:9:26:12 | C2.this |
1414
| variables.kt:27:9:27:12 | this |
1515
| variables.kt:28:9:28:12 | this |
16-
| variables.kt:31:9:31:15 | this |
17-
| variables.kt:32:9:32:15 | this |
16+
| variables.kt:31:9:31:15 | C2.this |
17+
| variables.kt:32:9:32:15 | C2.this |
1818
| variables.kt:41:13:41:16 | this |
1919
| variables.kt:42:13:42:19 | C3.this |
2020
instAccQualifier
21+
| variables.kt:26:9:26:12 | C2.this | variables.kt:26:9:26:12 | C2 |
22+
| variables.kt:31:9:31:15 | C2.this | variables.kt:31:9:31:15 | C2 |
23+
| variables.kt:32:9:32:15 | C2.this | variables.kt:32:9:32:15 | C2 |
2124
| variables.kt:42:13:42:19 | C3.this | variables.kt:42:13:42:19 | C3 |

0 commit comments

Comments
 (0)