Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use compiler version as the max value for api level when known #2956

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isKotlinNative
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
import kotlin.reflect.KProperty1
Expand Down Expand Up @@ -84,30 +83,23 @@ fun IKotlinFacetSettings.initializeIfNeeded(

if (shouldInferAPILevel) {
apiLevel = when {
useProjectSettings -> {
LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
}
/*
The below 'getLibraryVersion' call tries to figure out apiVersion by inspecting the stdlib available in dependencies.
This is not supported for K/N (07.2023), we therefore just fallback to the compiler version
*/
targetPlatform?.idePlatformKind?.isKotlinNative == true && compilerVersion != null -> {
languageLevel?.coerceAtMostVersion(compilerVersion)
}

else -> run apiLevel@{
val maximumValue = getKotlinStdlibVersionOrNull(
module,
rootModel,
this.targetPlatform?.idePlatformKind,
coerceRuntimeLibraryVersionToReleased = compilerVersion == null
) ?: compilerVersion ?: getDefaultVersion()
languageLevel?.coerceAtMostVersion(maximumValue)
}
useProjectSettings -> LanguageVersion.fromVersionString(commonArguments.apiVersion) ?: languageLevel
else -> languageLevel?.coerceAtMostVersion(getMaximumValueForApiLevel(module, rootModel, compilerVersion))
}
}
}

private fun IKotlinFacetSettings.getMaximumValueForApiLevel(
module: Module,
rootModel: ModuleRootModel?,
compilerVersion: IdeKotlinVersion?
) = compilerVersion ?: getKotlinStdlibVersionOrNull(
module,
rootModel,
targetPlatform?.idePlatformKind,
coerceRuntimeLibraryVersionToReleased = true
) ?: getDefaultVersion(explicitVersion = null, coerceRuntimeLibraryVersionToReleased = true)

private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?): TargetPlatform {
val platformKind = IdePlatformKind.ALL_KINDS.firstOrNull {
getRuntimeLibraryVersions(module, rootModel, it).any()
Expand Down