Kotlin: Handle forAllMethodsWithBody being removed

Per:
    commit 28797a31b4d9b7f5c99d162ab19fc6b46f8e529d
    Author: Alexander Udalov <alexander.udalov@jetbrains.com>
    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
    [...]
This commit is contained in:
Ian Lynagh
2024-02-13 15:48:26 +00:00
parent cd00a4dacd
commit 1b40b595fa
3 changed files with 20 additions and 5 deletions

View File

@@ -1617,8 +1617,9 @@ open class KotlinFileExtractor(
cls.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
private fun needsInterfaceForwarder(f: IrFunction) =
// forAllMethodsWithBody means -Xjvm-default=all or all-compatibility, in which case real
// Java default interfaces are used, and we don't need to do anything.
// jvmDefaultModeEnabledIsEnabled means that -Xjvm-default=all or all-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
// create a synthetic method like
// `int f(int x) { return super.InterfaceWithDefault.f(x); }`, because kotlinc will generate
@@ -1626,9 +1627,9 @@ 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.
!pluginContext.languageVersionSettings
.getFlag(JvmAnalysisFlags.jvmDefaultMode)
.forAllMethodsWithBody &&
!jvmDefaultModeEnabledIsEnabled(
pluginContext.languageVersionSettings
.getFlag(JvmAnalysisFlags.jvmDefaultMode)) &&
f.parentClassOrNull.let {
it != null &&
it.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB &&

View File

@@ -0,0 +1,7 @@
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 jvmDefaultModeEnabledIsEnabled(jdm: JvmDefaultMode): Boolean {
return jdm.isEnabled
}