diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt index 4f5db32620e..ff4a541459a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/facet/KotlinVersionInfoProvider.kt @@ -52,20 +52,24 @@ fun getRuntimeLibraryVersions( fun getLibraryLanguageLevel( module: Module, rootModel: ModuleRootModel?, - targetPlatform: TargetPlatformKind<*>? + targetPlatform: TargetPlatformKind<*>?, + coerceRuntimeLibraryVersionToReleased: Boolean = true ): LanguageVersion { - val minVersion = (getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM) + - VersionView.RELEASED_VERSION.versionString).minWith(VersionComparatorUtil.COMPARATOR) - return getDefaultLanguageLevel(module, minVersion) + val minVersion = getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM) + .addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased) + .minWith(VersionComparatorUtil.COMPARATOR) + return getDefaultLanguageLevel(module, minVersion, coerceRuntimeLibraryVersionToReleased) } fun getDefaultLanguageLevel( module: Module, - explicitVersion: String? = null + explicitVersion: String? = null, + coerceRuntimeLibraryVersionToReleased: Boolean = true ): LanguageVersion { val libVersion = explicitVersion - ?: (KotlinVersionInfoProvider.EP_NAME.extensions - .mapNotNull { it.getCompilerVersion(module) } + VersionView.RELEASED_VERSION.versionString) + ?: KotlinVersionInfoProvider.EP_NAME.extensions + .mapNotNull { it.getCompilerVersion(module) } + .addReleaseVersionIfNecessary(coerceRuntimeLibraryVersionToReleased) .minWith(VersionComparatorUtil.COMPARATOR) ?: return VersionView.RELEASED_VERSION return when { @@ -77,6 +81,9 @@ fun getDefaultLanguageLevel( } } +private fun Iterable.addReleaseVersionIfNecessary(shouldAdd: Boolean): Iterable = + if (shouldAdd) this + VersionView.RELEASED_VERSION.versionString else this + fun getRuntimeLibraryVersion(module: Module): String? { val targetPlatform = KotlinFacetSettingsProvider.getInstance(module.project).getInitializedSettings(module).targetPlatformKind val versions = getRuntimeLibraryVersions(module, null, targetPlatform ?: TargetPlatformKind.DEFAULT_PLATFORM) diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 7228b69b99f..8690cba8947 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -82,14 +82,21 @@ fun KotlinFacetSettings.initializeIfNeeded( if (shouldInferLanguageLevel) { languageLevel = (if (useProjectSettings) LanguageVersion.fromVersionString(commonArguments.languageVersion) else null) - ?: getDefaultLanguageLevel(module, compilerVersion) + ?: getDefaultLanguageLevel(module, compilerVersion, coerceRuntimeLibraryVersionToReleased = compilerVersion == null) } if (shouldInferAPILevel) { apiLevel = if (useProjectSettings) { LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel } else { - languageLevel!!.coerceAtMost(getLibraryLanguageLevel(module, rootModel, targetPlatformKind)) + languageLevel!!.coerceAtMost( + getLibraryLanguageLevel( + module, + rootModel, + targetPlatformKind, + coerceRuntimeLibraryVersionToReleased = compilerVersion == null + ) + ) } } }