From 453d38b0f78a2aa4066e5c848f60045f0123fbc9 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 15 Dec 2017 23:18:32 +0300 Subject: [PATCH] Do not set api version to language version when language version is null #KT-21852 fixed #KT-21574 fixed Original commit: 3f082346aea70f3be814fe24a6508b200cb92b26 --- .../kotlin/jps/build/KotlinJpsBuildTest.kt | 13 +++++++++++++ .../KotlinCommonCompilerArgumentsSerializer.kt | 5 ++--- .../kotlinProject.iml | 12 ++++++++++++ .../kotlinProject.ipr | 17 +++++++++++++++++ .../src/main.kt | 5 +++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.iml create mode 100644 jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.ipr create mode 100644 jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/src/main.kt diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index 238f0029c11..7ada9571307 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -638,6 +638,19 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { assertFilesNotExistInOutput(myProject.modules.get(0), "_DefaultPackage.class") } + fun testDefaultLanguageVersionCustomApiVersion() { + initProject(JVM_FULL_RUNTIME) + buildAllModules().assertFailed() + + assertEquals(1, myProject.modules.size) + val module = myProject.modules.first() + val args = JpsKotlinCompilerSettings.getCommonCompilerArguments(module) + args.apiVersion = "1.2" + JpsKotlinCompilerSettings.setCommonCompilerArguments(myProject, args) + + buildAllModules().assertSuccessful() + } + fun testKotlinJavaProject() { doTestWithRuntime() } diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt index 230fb208610..078f7513375 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/model/KotlinCommonCompilerArgumentsSerializer.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.jps.model import com.intellij.util.text.VersionComparatorUtil import org.jetbrains.jps.model.JpsProject import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.setApiVersionToLanguageVersionIfNeeded import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION import org.jetbrains.kotlin.jps.JpsKotlinCompilerSettings @@ -26,9 +27,7 @@ internal class KotlinCommonCompilerArgumentsSerializer : BaseJpsCompilerSettings KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION, CommonCompilerArguments::DummyImpl ) { override fun onLoad(project: JpsProject, settings: CommonCompilerArguments.DummyImpl) { - if (VersionComparatorUtil.compare(settings.languageVersion, settings.apiVersion) < 0) { - settings.apiVersion = settings.languageVersion - } + settings.setApiVersionToLanguageVersionIfNeeded() JpsKotlinCompilerSettings.setCommonCompilerArguments(project, settings) } } diff --git a/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.iml b/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.iml new file mode 100644 index 00000000000..d04ecd6e02e --- /dev/null +++ b/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.ipr b/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.ipr new file mode 100644 index 00000000000..001ea3380cd --- /dev/null +++ b/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/kotlinProject.ipr @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/src/main.kt b/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/src/main.kt new file mode 100644 index 00000000000..bf1bc16df8e --- /dev/null +++ b/jps/jps-plugin/testData/general/DefaultLanguageVersionCustomApiVersion/src/main.kt @@ -0,0 +1,5 @@ +package test + +fun main(args: Array) { + arrayListOf(1, 2, 3).fill(0) +} \ No newline at end of file