Fix handling of X/jvm-default intermediate modes such as 'compatibility', the new default as of 2.2.0

This commit is contained in:
Chris Smowton
2025-05-13 18:10:21 +01:00
parent 3001d0bd1c
commit fecad025de
6 changed files with 23 additions and 16 deletions

View File

@@ -1608,7 +1608,7 @@ open class KotlinFileExtractor(
cls.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
private fun needsInterfaceForwarder(f: IrFunction) =
// jvmDefaultModeEnabledIsEnabled means that -Xjvm-default=all or all-compatibility was
// jvmDefaultModeIsNoCompatibility means that -Xjvm-default=all or =no-compatibility was
// used, in which case real Java default interfaces are used, and we don't need to do
// anything.
// Otherwise, for a Kotlin-defined method inheriting a Kotlin-defined default, we need to
@@ -1618,7 +1618,7 @@ open class KotlinFileExtractor(
// (NB. kotlinc's actual implementation strategy is different -- it makes an inner class
// called InterfaceWithDefault$DefaultImpls and stores the default methods
// there to allow default method usage in Java < 8, but this is hopefully niche.
!jvmDefaultModeEnabledIsEnabled(getJvmDefaultMode(pluginContext.languageVersionSettings)) &&
!jvmDefaultModeIsNoCompatibility(getJvmDefaultMode(pluginContext.languageVersionSettings)) &&
f.parentClassOrNull.let {
it != null &&
it.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB &&

View File

@@ -1,7 +0,0 @@
package com.github.codeql.utils.versions
import org.jetbrains.kotlin.config.JvmDefaultMode
fun jvmDefaultModeEnabledIsEnabled(jdm: JvmDefaultMode): Boolean {
return jdm.forAllMethodsWithBody
}

View File

@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions
import org.jetbrains.kotlin.config.JvmDefaultMode
fun jvmDefaultModeIsNoCompatibility(jdm: JvmDefaultMode): Boolean {
return jdm == JvmDefaultMode.ALL_INCOMPATIBLE
}

View File

@@ -1,7 +0,0 @@
package com.github.codeql.utils.versions
import org.jetbrains.kotlin.config.JvmDefaultMode
fun jvmDefaultModeEnabledIsEnabled(jdm: JvmDefaultMode): Boolean {
return jdm.isEnabled
}

View File

@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions
import org.jetbrains.kotlin.config.JvmDefaultMode
fun jvmDefaultModeIsNoCompatibility(jdm: JvmDefaultMode): Boolean {
return jdm == JvmDefaultMode.ALL
}

View File

@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions
import org.jetbrains.kotlin.config.JvmDefaultMode
fun jvmDefaultModeIsNoCompatibility(jdm: JvmDefaultMode): Boolean {
return jdm == JvmDefaultMode.NO_COMPATIBILITY
}