Skip to content

Commit 6457e05

Browse files
committed
Kotlin: Fix extraction of $default extension functions
1 parent 43f2380 commit 6457e05

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,10 @@ open class KotlinFileExtractor(
975975
val methodId = id.cast<DbMethod>()
976976
extractMethod(methodId, locId, shortName, erase(f.returnType), paramsSignature, parentId, methodId, origin = null, extractTypeAccess = extractMethodAndParameterTypeAccesses)
977977
addModifiers(id, "static")
978+
if (extReceiver != null) {
979+
val extendedType = allParamTypeResults[0] // TODO: this is not correct for member extension methods, where the dispatch receiver is the first parameter
980+
tw.writeKtExtensionFunctions(methodId, extendedType.javaResult.id, extendedType.kotlinResult.id)
981+
}
978982
}
979983
tw.writeHasLocation(id, locId)
980984
if (f.visibility != DescriptorVisibilities.PRIVATE && f.visibility != DescriptorVisibilities.PRIVATE_TO_THIS) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@
306306
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt(...) | MethodAccess |
307307
| methods3.kt:3:1:3:49 | int | TypeAccess |
308308
| methods3.kt:3:1:3:49 | int | TypeAccess |
309-
| methods3.kt:3:1:3:49 | p0 | VarAccess |
310309
| methods3.kt:3:1:3:49 | p1 | VarAccess |
311310
| methods3.kt:3:1:3:49 | p1 | VarAccess |
312311
| methods3.kt:3:1:3:49 | p2 | VarAccess |
312+
| methods3.kt:3:1:3:49 | this | ExtensionReceiverAccess |
313313
| methods3.kt:3:5:3:10 | String | TypeAccess |
314314
| methods3.kt:3:36:3:45 | int | TypeAccess |
315315
| methods3.kt:3:45:3:45 | 1 | IntegerLiteral |
@@ -326,11 +326,11 @@
326326
| methods3.kt:6:5:6:45 | fooBarMethodExt(...) | MethodAccess |
327327
| methods3.kt:6:5:6:45 | int | TypeAccess |
328328
| methods3.kt:6:5:6:45 | int | TypeAccess |
329-
| methods3.kt:6:5:6:45 | p0 | VarAccess |
330329
| methods3.kt:6:5:6:45 | p1 | VarAccess |
331330
| methods3.kt:6:5:6:45 | p2 | VarAccess |
332331
| methods3.kt:6:5:6:45 | p2 | VarAccess |
333332
| methods3.kt:6:5:6:45 | p3 | VarAccess |
333+
| methods3.kt:6:5:6:45 | this | ExtensionReceiverAccess |
334334
| methods3.kt:6:9:6:14 | String | TypeAccess |
335335
| methods3.kt:6:32:6:41 | int | TypeAccess |
336336
| methods3.kt:6:41:6:41 | 1 | IntegerLiteral |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ constructors
7777
| methods.kt:5:1:20:1 | Class | methods.kt:5:1:20:1 | Class | Class() |
7878
extensions
7979
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | file:///modules/java.base/java/lang/String.class:0:0:0:0 | String |
80+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default | file:///modules/java.base/java/lang/String.class:0:0:0:0 | String |
8081
| methods3.kt:6:5:6:45 | fooBarMethodExt | file:///modules/java.base/java/lang/String.class:0:0:0:0 | String |
82+
| methods3.kt:6:5:6:45 | fooBarMethodExt$default | file:///modules/java.base/java/lang/String.class:0:0:0:0 | String |
8183
| methods5.kt:9:3:9:32 | f1 | file:///!unknown-binary-location/foo/bar/C1.class:0:0:0:0 | C1<T1> |
8284
extensionsMismatch
83-
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default |
84-
| methods3.kt:6:5:6:45 | fooBarMethodExt | methods3.kt:6:5:6:45 | fooBarMethodExt$default |

0 commit comments

Comments
 (0)