Move default implementation of TargetPlatform.platformName to leaf classes
Otherwise, we have a static initialization loop, leading to null-leaks Removing default interface method indeed disconnects the loop, as per JVM Specification, "5.5 Initialization". See KT-33245 for detailed explanations ^KT-33245 Fixed
This commit is contained in:
@@ -16,10 +16,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
interface CommonPlatform : TargetPlatform {
|
||||
@JvmDefault
|
||||
override val platformName: String
|
||||
get() = "Default"
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE: CommonPlatform = CommonPlatforms.CompatCommonPlatform
|
||||
|
||||
@@ -25,7 +25,10 @@ object CommonPlatforms {
|
||||
defaultJsPlatform.single(),
|
||||
defaultKonanPlatform.single()
|
||||
)
|
||||
), org.jetbrains.kotlin.analyzer.common.CommonPlatform
|
||||
), org.jetbrains.kotlin.analyzer.common.CommonPlatform {
|
||||
override val platformName: String
|
||||
get() = "Default"
|
||||
}
|
||||
|
||||
val defaultCommonPlatform: TargetPlatform
|
||||
get() = CompatCommonPlatform
|
||||
|
||||
@@ -24,7 +24,10 @@ object KonanPlatforms {
|
||||
)
|
||||
object CompatKonanPlatform : TargetPlatform(setOf(DefaultSimpleKonanPlatform)),
|
||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
||||
org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform {}
|
||||
org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform {
|
||||
override val platformName: String
|
||||
get() = "Native"
|
||||
}
|
||||
|
||||
val defaultKonanPlatform: TargetPlatform
|
||||
get() = CompatKonanPlatform
|
||||
|
||||
-4
@@ -16,10 +16,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
interface KonanPlatform : TargetPlatform {
|
||||
@JvmDefault
|
||||
override val platformName: String
|
||||
get() = "Native"
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE: KonanPlatform = KonanPlatforms.CompatKonanPlatform
|
||||
|
||||
@@ -45,7 +45,10 @@ object JvmPlatforms {
|
||||
)
|
||||
object CompatJvmPlatform : TargetPlatform(setOf(UNSPECIFIED_SIMPLE_JVM_PLATFORM)),
|
||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
||||
org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform {}
|
||||
org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform {
|
||||
override val platformName: String
|
||||
get() = "JVM"
|
||||
}
|
||||
}
|
||||
|
||||
class JdkPlatform(val targetVersion: JvmTarget) : JvmPlatform() {
|
||||
|
||||
@@ -16,10 +16,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
interface JvmPlatform : TargetPlatform {
|
||||
@JvmDefault
|
||||
override val platformName: String
|
||||
get() = "JVM"
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE: JvmPlatform = JvmPlatforms.CompatJvmPlatform
|
||||
|
||||
@@ -27,10 +27,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
interface JsPlatform : TargetPlatform {
|
||||
@JvmDefault
|
||||
override val platformName: String
|
||||
get() = "JS"
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val INSTANCE: JsPlatform = JsPlatforms.CompatJsPlatform
|
||||
|
||||
@@ -24,7 +24,10 @@ object JsPlatforms {
|
||||
)
|
||||
object CompatJsPlatform : TargetPlatform(setOf(DefaultSimpleJsPlatform)),
|
||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
||||
org.jetbrains.kotlin.js.resolve.JsPlatform {}
|
||||
org.jetbrains.kotlin.js.resolve.JsPlatform {
|
||||
override val platformName: String
|
||||
get() = "JS"
|
||||
}
|
||||
|
||||
val defaultJsPlatform: TargetPlatform
|
||||
get() = CompatJsPlatform
|
||||
|
||||
Reference in New Issue
Block a user