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:
Dmitry Savvinov
2019-08-12 12:26:50 +03:00
parent 555e1a35e9
commit 0065236bde
8 changed files with 16 additions and 20 deletions
@@ -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