Skip to content

Commit 1b40b59

Browse files
committed
Kotlin: Handle forAllMethodsWithBody being removed
Per: commit 28797a31b4d9b7f5c99d162ab19fc6b46f8e529d Author: Alexander Udalov <[email protected]> Date: Thu Feb 1 13:22:48 2024 +0100 JVM: refactor JvmDefaultMode, remove/rename some entries [...] - remove forAllMethodsWithBody because its behavior is now equivalent to isEnabled [...]
1 parent cd00a4d commit 1b40b59

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,18 +1617,19 @@ open class KotlinFileExtractor(
16171617
cls.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
16181618

16191619
private fun needsInterfaceForwarder(f: IrFunction) =
1620-
// forAllMethodsWithBody means -Xjvm-default=all or all-compatibility, in which case real
1621-
// Java default interfaces are used, and we don't need to do anything.
1620+
// jvmDefaultModeEnabledIsEnabled means that -Xjvm-default=all or all-compatibility was
1621+
// used, in which case real Java default interfaces are used, and we don't need to do
1622+
// anything.
16221623
// Otherwise, for a Kotlin-defined method inheriting a Kotlin-defined default, we need to
16231624
// create a synthetic method like
16241625
// `int f(int x) { return super.InterfaceWithDefault.f(x); }`, because kotlinc will generate
16251626
// a public method and Java callers may directly target it.
16261627
// (NB. kotlinc's actual implementation strategy is different -- it makes an inner class
16271628
// called InterfaceWithDefault$DefaultImpls and stores the default methods
16281629
// there to allow default method usage in Java < 8, but this is hopefully niche.
1629-
!pluginContext.languageVersionSettings
1630-
.getFlag(JvmAnalysisFlags.jvmDefaultMode)
1631-
.forAllMethodsWithBody &&
1630+
!jvmDefaultModeEnabledIsEnabled(
1631+
pluginContext.languageVersionSettings
1632+
.getFlag(JvmAnalysisFlags.jvmDefaultMode)) &&
16321633
f.parentClassOrNull.let {
16331634
it != null &&
16341635
it.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB &&
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.config.JvmDefaultMode
4+
5+
fun jvmDefaultModeEnabledIsEnabled(jdm: JvmDefaultMode): Boolean {
6+
return jdm.forAllMethodsWithBody
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.config.JvmDefaultMode
4+
5+
fun jvmDefaultModeEnabledIsEnabled(jdm: JvmDefaultMode): Boolean {
6+
return jdm.isEnabled
7+
}

0 commit comments

Comments
 (0)