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
|
level = DeprecationLevel.ERROR
|
||||||
)
|
)
|
||||||
interface CommonPlatform : TargetPlatform {
|
interface CommonPlatform : TargetPlatform {
|
||||||
@JvmDefault
|
|
||||||
override val platformName: String
|
|
||||||
get() = "Default"
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val INSTANCE: CommonPlatform = CommonPlatforms.CompatCommonPlatform
|
val INSTANCE: CommonPlatform = CommonPlatforms.CompatCommonPlatform
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ object CommonPlatforms {
|
|||||||
defaultJsPlatform.single(),
|
defaultJsPlatform.single(),
|
||||||
defaultKonanPlatform.single()
|
defaultKonanPlatform.single()
|
||||||
)
|
)
|
||||||
), org.jetbrains.kotlin.analyzer.common.CommonPlatform
|
), org.jetbrains.kotlin.analyzer.common.CommonPlatform {
|
||||||
|
override val platformName: String
|
||||||
|
get() = "Default"
|
||||||
|
}
|
||||||
|
|
||||||
val defaultCommonPlatform: TargetPlatform
|
val defaultCommonPlatform: TargetPlatform
|
||||||
get() = CompatCommonPlatform
|
get() = CompatCommonPlatform
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ object KonanPlatforms {
|
|||||||
)
|
)
|
||||||
object CompatKonanPlatform : TargetPlatform(setOf(DefaultSimpleKonanPlatform)),
|
object CompatKonanPlatform : TargetPlatform(setOf(DefaultSimpleKonanPlatform)),
|
||||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
// 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
|
val defaultKonanPlatform: TargetPlatform
|
||||||
get() = CompatKonanPlatform
|
get() = CompatKonanPlatform
|
||||||
|
|||||||
-4
@@ -16,10 +16,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
|||||||
level = DeprecationLevel.ERROR
|
level = DeprecationLevel.ERROR
|
||||||
)
|
)
|
||||||
interface KonanPlatform : TargetPlatform {
|
interface KonanPlatform : TargetPlatform {
|
||||||
@JvmDefault
|
|
||||||
override val platformName: String
|
|
||||||
get() = "Native"
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val INSTANCE: KonanPlatform = KonanPlatforms.CompatKonanPlatform
|
val INSTANCE: KonanPlatform = KonanPlatforms.CompatKonanPlatform
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ object JvmPlatforms {
|
|||||||
)
|
)
|
||||||
object CompatJvmPlatform : TargetPlatform(setOf(UNSPECIFIED_SIMPLE_JVM_PLATFORM)),
|
object CompatJvmPlatform : TargetPlatform(setOf(UNSPECIFIED_SIMPLE_JVM_PLATFORM)),
|
||||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
// 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() {
|
class JdkPlatform(val targetVersion: JvmTarget) : JvmPlatform() {
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
|||||||
level = DeprecationLevel.ERROR
|
level = DeprecationLevel.ERROR
|
||||||
)
|
)
|
||||||
interface JvmPlatform : TargetPlatform {
|
interface JvmPlatform : TargetPlatform {
|
||||||
@JvmDefault
|
|
||||||
override val platformName: String
|
|
||||||
get() = "JVM"
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val INSTANCE: JvmPlatform = JvmPlatforms.CompatJvmPlatform
|
val INSTANCE: JvmPlatform = JvmPlatforms.CompatJvmPlatform
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
|||||||
level = DeprecationLevel.ERROR
|
level = DeprecationLevel.ERROR
|
||||||
)
|
)
|
||||||
interface JsPlatform : TargetPlatform {
|
interface JsPlatform : TargetPlatform {
|
||||||
@JvmDefault
|
|
||||||
override val platformName: String
|
|
||||||
get() = "JS"
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val INSTANCE: JsPlatform = JsPlatforms.CompatJsPlatform
|
val INSTANCE: JsPlatform = JsPlatforms.CompatJsPlatform
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ object JsPlatforms {
|
|||||||
)
|
)
|
||||||
object CompatJsPlatform : TargetPlatform(setOf(DefaultSimpleJsPlatform)),
|
object CompatJsPlatform : TargetPlatform(setOf(DefaultSimpleJsPlatform)),
|
||||||
// Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions
|
// 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
|
val defaultJsPlatform: TargetPlatform
|
||||||
get() = CompatJsPlatform
|
get() = CompatJsPlatform
|
||||||
|
|||||||
Reference in New Issue
Block a user