Report a warning or error if an old language version or API version is used
#KT-25823 Fixed
This commit is contained in:
committed by
Ilya Gorbunov
parent
db29eadba5
commit
02a9b03007
+12
@@ -304,6 +304,18 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deprecatedVersion = when {
|
||||||
|
languageVersion < LanguageVersion.FIRST_SUPPORTED -> "Language version ${languageVersion.versionString}"
|
||||||
|
apiVersion < LanguageVersion.FIRST_SUPPORTED -> "API version ${apiVersion.versionString}"
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
if (deprecatedVersion != null) {
|
||||||
|
collector.report(
|
||||||
|
CompilerMessageSeverity.STRONG_WARNING,
|
||||||
|
"$deprecatedVersion is deprecated and its support will be removed in a future version of Kotlin"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (progressiveMode && languageVersion < LanguageVersion.LATEST_STABLE) {
|
if (progressiveMode && languageVersion < LanguageVersion.LATEST_STABLE) {
|
||||||
collector.report(
|
collector.report(
|
||||||
CompilerMessageSeverity.STRONG_WARNING,
|
CompilerMessageSeverity.STRONG_WARNING,
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/languageVersion.kt
|
|||||||
-output
|
-output
|
||||||
$TEMP_DIR$/out.js
|
$TEMP_DIR$/out.js
|
||||||
-language-version
|
-language-version
|
||||||
1.0
|
1.2
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
sealed class Base
|
annotation class Outer {
|
||||||
|
class Nested
|
||||||
class Derived : Base()
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
compiler/testData/cli/js/languageVersion.kt:5:17: error: this type is sealed, so it can be inherited by only its own nested classes or objects
|
compiler/testData/cli/js/languageVersion.kt:4:5: error: members are not allowed in annotation class
|
||||||
class Derived : Base()
|
class Nested
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/apiVersion.kt
|
|||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
-api-version
|
-api-version
|
||||||
1.0
|
1.2
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
fun test() {
|
fun test() {
|
||||||
""::class.isInstance(42)
|
""::class.sealedSubclasses
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -1,7 +1,4 @@
|
|||||||
compiler/testData/cli/jvm/apiVersion.kt:2:5: error: the feature "bound callable references" is only available since API version 1.1
|
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||||
""::class.isInstance(42)
|
""::class.sealedSubclasses
|
||||||
^
|
|
||||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
warning: language version 1.1 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
compiler/testData/cli/jvm/apiVersion1.0.kt:8:1: error: the feature "coroutines" is only available since API version 1.1 (see: https://kotlinlang.org/docs/diagnostics/experimental-coroutines)
|
compiler/testData/cli/jvm/apiVersion1.0.kt:8:1: error: the feature "coroutines" is only available since API version 1.1 (see: https://kotlinlang.org/docs/diagnostics/experimental-coroutines)
|
||||||
suspend fun test() {
|
suspend fun test() {
|
||||||
^
|
^
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/apiVersionAndSinceNewerKotlin.kt
|
|||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
-api-version
|
-api-version
|
||||||
1.0
|
1.2
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@SinceKotlin("1.0")
|
@SinceKotlin("1.2")
|
||||||
fun old() {}
|
fun old() {}
|
||||||
|
|
||||||
@SinceKotlin("1.1")
|
@SinceKotlin("1.3")
|
||||||
fun new() {}
|
fun new() {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
compiler/testData/cli/jvm/apiVersionAndSinceNewerKotlin.kt:4:1: warning: the version is greater than the specified API version 1.0
|
compiler/testData/cli/jvm/apiVersionAndSinceNewerKotlin.kt:4:1: warning: the version is greater than the specified API version 1.2
|
||||||
@SinceKotlin("1.1")
|
@SinceKotlin("1.3")
|
||||||
^
|
^
|
||||||
OK
|
OK
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ $TESTDATA_DIR$/apiVersion.kt
|
|||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
-api-version
|
-api-version
|
||||||
1.1
|
1.3
|
||||||
-language-version
|
-language-version
|
||||||
1.0
|
1.2
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
error: -api-version (1.1) cannot be greater than -language-version (1.0)
|
error: -api-version (1.3) cannot be greater than -language-version (1.2)
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
$TESTDATA_DIR$/apiVersion.kt -d $TEMP_DIR$ -api-version 1.0 -language-version 1.1
|
$TESTDATA_DIR$/apiVersion.kt -d $TEMP_DIR$ -api-version 1.2 -language-version 1.3
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ $TESTDATA_DIR$/apiVersion.kt
|
|||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
-api-version
|
-api-version
|
||||||
1.0
|
1.2
|
||||||
-language-version
|
-language-version
|
||||||
1.1
|
1.3
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
compiler/testData/cli/jvm/apiVersion.kt:2:5: error: the feature "bound callable references" is only available since API version 1.1
|
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||||
""::class.isInstance(42)
|
""::class.sealedSubclasses
|
||||||
^
|
|
||||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
compiler/testData/cli/jvm/apiVersion.kt:2:5: error: the feature "bound callable references" is only available since API version 1.1
|
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||||
""::class.isInstance(42)
|
""::class.sealedSubclasses
|
||||||
^
|
|
||||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
-X"some escaped \" sequence \\"
|
-X"some escaped \" sequence \\"
|
||||||
$TESTDATA_DIR$/apiVersion.kt
|
$TESTDATA_DIR$/apiVersion.kt
|
||||||
-d
|
-d
|
||||||
$TEMP_DIR$ -api-version 1.0 -language-version 1.1
|
$TEMP_DIR$ -api-version 1.2 -language-version 1.3
|
||||||
|
|||||||
+2
-5
@@ -1,8 +1,5 @@
|
|||||||
warning: flag is not supported by this version of the compiler: -Xsome escaped " sequence /
|
warning: flag is not supported by this version of the compiler: -Xsome escaped " sequence /
|
||||||
compiler/testData/cli/jvm/apiVersion.kt:2:5: error: the feature "bound callable references" is only available since API version 1.1
|
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||||
""::class.isInstance(42)
|
""::class.sealedSubclasses
|
||||||
^
|
|
||||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-api-version
|
||||||
|
1.1
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: API version 1.1 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
|
OK
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
$TESTDATA_DIR$/simple.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
|
-language-version
|
||||||
|
1.1
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
warning: language version 1.1 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
|
OK
|
||||||
@@ -7,6 +7,7 @@ This mode is not recommended for production use,
|
|||||||
as no stability/compatibility guarantees are given on
|
as no stability/compatibility guarantees are given on
|
||||||
compiler or generated code. Use it at your own risk!
|
compiler or generated code. Use it at your own risk!
|
||||||
|
|
||||||
|
warning: language version 1.1 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
compiler/testData/cli/jvm/legacySmartCastsAfterTry.kt:8:9: error: only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
|
compiler/testData/cli/jvm/legacySmartCastsAfterTry.kt:8:9: error: only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
|
||||||
some.length
|
some.length
|
||||||
^
|
^
|
||||||
|
|||||||
+1
-1
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/languageVersion.kt
|
|||||||
-d
|
-d
|
||||||
$TEMP_DIR$
|
$TEMP_DIR$
|
||||||
-language-version
|
-language-version
|
||||||
1.0
|
1.2
|
||||||
|
|||||||
+2
-6
@@ -1,9 +1,5 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
sealed class Base
|
annotation class Outer {
|
||||||
|
class Nested
|
||||||
class Derived : Base()
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
""::class.isInstance(42)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-8
@@ -1,10 +1,4 @@
|
|||||||
compiler/testData/cli/jvm/languageVersion.kt:5:17: error: this type is sealed, so it can be inherited by only its own nested classes or objects
|
compiler/testData/cli/jvm/languageVersion.kt:4:5: error: members are not allowed in annotation class
|
||||||
class Derived : Base()
|
class Nested
|
||||||
^
|
|
||||||
compiler/testData/cli/jvm/languageVersion.kt:8:5: error: the feature "bound callable references" is only available since language version 1.1
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
^
|
||||||
compiler/testData/cli/jvm/languageVersion.kt:8:15: error: unresolved reference: isInstance
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
@@ -1 +1 @@
|
|||||||
$TEMP_DIR$ -api-version 1.0 -language-version 1.1
|
$TEMP_DIR$ -api-version 1.2 -language-version 1.3
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
compiler/testData/cli/jvm/apiVersion.kt:2:5: error: the feature "bound callable references" is only available since API version 1.1
|
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||||
""::class.isInstance(42)
|
""::class.sealedSubclasses
|
||||||
^
|
|
||||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
|
||||||
""::class.isInstance(42)
|
|
||||||
^
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
warning: language version 1.0 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
compiler/testData/cli/jvm/unsupportedTypeAlias.kt:3:1: error: the feature "type aliases" is only available since language version 1.1
|
compiler/testData/cli/jvm/unsupportedTypeAlias.kt:3:1: error: the feature "type aliases" is only available since language version 1.1
|
||||||
typealias Unused = String
|
typealias Unused = String
|
||||||
^
|
^
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
warning: language version 1.0 is deprecated and its support will be removed in a future version of Kotlin
|
||||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:2:13: error: unresolved reference: Str
|
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:2:13: error: unresolved reference: Str
|
||||||
import test.Str
|
import test.Str
|
||||||
^
|
^
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ Buildfile: [TestData]/build.xml
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
[kotlinc] Compiling [[TestData]/main.kt] => [[Temp]/hello.jar]
|
[kotlinc] Compiling [[TestData]/main.kt] => [[Temp]/hello.jar]
|
||||||
[kotlinc] [TestData]/main.kt:3:17: error: this type is sealed, so it can be inherited by only its own nested classes or objects
|
[kotlinc] [TestData]/main.kt:2:5: error: members are not allowed in annotation class
|
||||||
[kotlinc] class Derived : Base()
|
[kotlinc] class Nested
|
||||||
[kotlinc] ^
|
[kotlinc] ^
|
||||||
|
|
||||||
ERR:
|
ERR:
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<target name="build">
|
<target name="build">
|
||||||
<kotlinc src="${test.data}/main.kt" output="${temp}/hello.jar">
|
<kotlinc src="${test.data}/main.kt" output="${temp}/hello.jar">
|
||||||
<compilerarg line="-language-version 1.0"/>
|
<compilerarg line="-language-version 1.2"/>
|
||||||
</kotlinc>
|
</kotlinc>
|
||||||
</target>
|
</target>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
sealed class Base
|
annotation class Outer {
|
||||||
|
class Nested
|
||||||
class Derived : Base()
|
}
|
||||||
|
|||||||
@@ -151,6 +151,16 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
runTest("compiler/testData/cli/jvm/coroutinesWarn.args");
|
runTest("compiler/testData/cli/jvm/coroutinesWarn.args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("deprecatedApiVersion.args")
|
||||||
|
public void testDeprecatedApiVersion() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/deprecatedApiVersion.args");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("deprecatedLanguageVersion.args")
|
||||||
|
public void testDeprecatedLanguageVersion() throws Exception {
|
||||||
|
runTest("compiler/testData/cli/jvm/deprecatedLanguageVersion.args");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("diagnosticsOrder.args")
|
@TestMetadata("diagnosticsOrder.args")
|
||||||
public void testDiagnosticsOrder() throws Exception {
|
public void testDiagnosticsOrder() throws Exception {
|
||||||
runTest("compiler/testData/cli/jvm/diagnosticsOrder.args");
|
runTest("compiler/testData/cli/jvm/diagnosticsOrder.args");
|
||||||
|
|||||||
+1
-1
@@ -251,7 +251,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
|||||||
fun testPreReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion() {
|
fun testPreReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion() {
|
||||||
withPreRelease(true) {
|
withPreRelease(true) {
|
||||||
val library = compileLibrary("library")
|
val library = compileLibrary("library")
|
||||||
val someStableReleasedVersion = LanguageVersion.values().first().also { assert(it.isStable) }
|
val someStableReleasedVersion = LanguageVersion.values().first { it.isStable && it >= LanguageVersion.FIRST_SUPPORTED }
|
||||||
compileKotlin(
|
compileKotlin(
|
||||||
"source.kt", tmpdir, listOf(library), K2JVMCompiler(),
|
"source.kt", tmpdir, listOf(library), K2JVMCompiler(),
|
||||||
listOf("-language-version", someStableReleasedVersion.versionString)
|
listOf("-language-version", someStableReleasedVersion.versionString)
|
||||||
|
|||||||
@@ -213,6 +213,9 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware {
|
|||||||
fun fromFullVersionString(str: String) =
|
fun fromFullVersionString(str: String) =
|
||||||
str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null }
|
str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null }
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val FIRST_SUPPORTED = KOTLIN_1_2
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val LATEST_STABLE = KOTLIN_1_3
|
val LATEST_STABLE = KOTLIN_1_3
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user