From 079343c093f34d664e1dc8e3ff9513a670e7c7a7 Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Fri, 17 Nov 2023 14:46:35 +0000 Subject: [PATCH] Return the default value if an illegal argument is passed.. ..to the TargetPlatform during the import process. #KTIJ-27718 Fixed Merge-request: KT-MR-13072 Merged-by: Aleksei Cherepanov --- .../kotlin/platform/impl/JvmIdePlatformKind.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt index cffdb9a561a..f253c18d903 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.platform.impl -import com.intellij.util.text.VersionComparatorUtil import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.JvmTarget @@ -21,15 +20,15 @@ import org.jetbrains.kotlin.platform.jvm.isJvm object JvmIdePlatformKind : IdePlatformKind() { override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isJvm() + private val jvmTargetDescriptionMap by lazy { + JvmTarget.values().associateBy { it.description } + } + override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? { if (arguments !is K2JVMCompilerArguments) return null - val jvmTargetDescription = arguments.jvmTarget - ?: return JvmPlatforms.defaultJvmPlatform - - val jvmTarget = JvmTarget.values() - .firstOrNull { VersionComparatorUtil.COMPARATOR.compare(it.description, jvmTargetDescription) >= 0 } - ?: return JvmPlatforms.defaultJvmPlatform + val jvmTargetDescription = arguments.jvmTarget ?: return JvmPlatforms.defaultJvmPlatform + val jvmTarget = jvmTargetDescriptionMap[jvmTargetDescription] ?: return JvmPlatforms.defaultJvmPlatform return JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget) }