Do not set api version to language version when language version is null
#KT-21852 fixed
#KT-21574 fixed
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.arguments
|
||||
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
@@ -98,4 +99,10 @@ fun <T : Any> collectProperties(kClass: KClass<T>, inheritedOnly: Boolean): List
|
||||
return properties.filter {
|
||||
it.visibility == KVisibility.PUBLIC && it.findAnnotation<Transient>() == null
|
||||
}
|
||||
}
|
||||
|
||||
fun CommonCompilerArguments.setApiVersionToLanguageVersionIfNeeded() {
|
||||
if (languageVersion != null && VersionComparatorUtil.compare(languageVersion, apiVersion) < 0) {
|
||||
apiVersion = languageVersion
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jdom.Element
|
||||
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.config.detectVersionAutoAdvance
|
||||
import org.jetbrains.kotlin.config.dropVersionsIfNecessary
|
||||
@@ -41,10 +42,7 @@ class KotlinCommonCompilerArgumentsHolder(project: Project) : BaseKotlinCompiler
|
||||
|
||||
update {
|
||||
// To fix earlier configurations with incorrect combination of language and API version
|
||||
if (VersionComparatorUtil.compare(languageVersion, apiVersion) < 0) {
|
||||
apiVersion = languageVersion
|
||||
}
|
||||
|
||||
setApiVersionToLanguageVersionIfNeeded()
|
||||
detectVersionAutoAdvance()
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="1.1" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/kotlin-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/module.iml" filepath="$PROJECT_DIR$/module.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.configuration
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
|
||||
@@ -121,4 +122,10 @@ class ConfigureKotlinInTempDirTest : AbstractConfigureKotlinTest() {
|
||||
val moduleFileContentAfter = String(module.moduleFile!!.contentsToByteArray())
|
||||
Assert.assertEquals(moduleFileContentBefore, moduleFileContentAfter)
|
||||
}
|
||||
|
||||
fun testApiVersionWithoutLanguageVersion() {
|
||||
KotlinCommonCompilerArgumentsHolder.getInstance(myProject)
|
||||
val settings = myProject.getLanguageVersionSettings()
|
||||
Assert.assertEquals(ApiVersion.KOTLIN_1_1, settings.apiVersion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
+2
-3
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -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>
|
||||
+17
@@ -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>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
arrayListOf(1, 2, 3).fill(0)
|
||||
}
|
||||
Reference in New Issue
Block a user