Do not set api version to language version when language version is null

#KT-21852 fixed
    #KT-21574 fixed

Original commit: 3f082346ae
This commit is contained in:
Alexey Tsvetkov
2017-12-15 23:18:32 +03:00
parent cf59f84273
commit 453d38b0f7
5 changed files with 49 additions and 3 deletions
@@ -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()
}
@@ -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)
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
</component>
</module>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="1.1" />
</component>
</project>
@@ -0,0 +1,5 @@
package test
fun main(args: Array<String>) {
arrayListOf(1, 2, 3).fill(0)
}