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) {
|
||||
collector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/languageVersion.kt
|
||||
-output
|
||||
$TEMP_DIR$/out.js
|
||||
-language-version
|
||||
1.0
|
||||
1.2
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
package test
|
||||
|
||||
sealed class Base
|
||||
|
||||
class Derived : Base()
|
||||
annotation class Outer {
|
||||
class Nested
|
||||
}
|
||||
|
||||
+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
|
||||
class Derived : Base()
|
||||
^
|
||||
compiler/testData/cli/js/languageVersion.kt:4:5: error: members are not allowed in annotation class
|
||||
class Nested
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/apiVersion.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-api-version
|
||||
1.0
|
||||
1.2
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
fun test() {
|
||||
""::class.isInstance(42)
|
||||
""::class.sealedSubclasses
|
||||
}
|
||||
|
||||
+3
-6
@@ -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
|
||||
""::class.isInstance(42)
|
||||
^
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
||||
""::class.isInstance(42)
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||
""::class.sealedSubclasses
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
COMPILATION_ERROR
|
||||
|
||||
+2
-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)
|
||||
suspend fun test() {
|
||||
^
|
||||
@@ -10,4 +11,4 @@ compiler/testData/cli/jvm/apiVersion1.0.kt:10:5: error: the feature "bound calla
|
||||
compiler/testData/cli/jvm/apiVersion1.0.kt:15:11: error: the feature "local delegated properties" is only available since API version 1.1
|
||||
val b by lazy { "" }
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/apiVersionAndSinceNewerKotlin.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-api-version
|
||||
1.0
|
||||
1.2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@SinceKotlin("1.0")
|
||||
@SinceKotlin("1.2")
|
||||
fun old() {}
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
@SinceKotlin("1.3")
|
||||
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
|
||||
@SinceKotlin("1.1")
|
||||
compiler/testData/cli/jvm/apiVersionAndSinceNewerKotlin.kt:4:1: warning: the version is greater than the specified API version 1.2
|
||||
@SinceKotlin("1.3")
|
||||
^
|
||||
OK
|
||||
|
||||
@@ -2,6 +2,6 @@ $TESTDATA_DIR$/apiVersion.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-api-version
|
||||
1.1
|
||||
1.3
|
||||
-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
|
||||
|
||||
@@ -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
|
||||
$TEMP_DIR$
|
||||
-api-version
|
||||
1.0
|
||||
1.2
|
||||
-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
|
||||
""::class.isInstance(42)
|
||||
^
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
||||
""::class.isInstance(42)
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||
""::class.sealedSubclasses
|
||||
^
|
||||
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
|
||||
""::class.isInstance(42)
|
||||
^
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
||||
""::class.isInstance(42)
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||
""::class.sealedSubclasses
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
-X"some escaped \" sequence \\"
|
||||
$TESTDATA_DIR$/apiVersion.kt
|
||||
-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 /
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:5: error: the feature "bound callable references" is only available since API version 1.1
|
||||
""::class.isInstance(42)
|
||||
^
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
||||
""::class.isInstance(42)
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||
""::class.sealedSubclasses
|
||||
^
|
||||
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
|
||||
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?
|
||||
some.length
|
||||
^
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ $TESTDATA_DIR$/languageVersion.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-language-version
|
||||
1.0
|
||||
1.2
|
||||
|
||||
+2
-6
@@ -1,9 +1,5 @@
|
||||
package test
|
||||
|
||||
sealed class Base
|
||||
|
||||
class Derived : Base()
|
||||
|
||||
fun test() {
|
||||
""::class.isInstance(42)
|
||||
annotation class Outer {
|
||||
class Nested
|
||||
}
|
||||
|
||||
+3
-9
@@ -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
|
||||
class Derived : Base()
|
||||
^
|
||||
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:4:5: error: members are not allowed in annotation class
|
||||
class Nested
|
||||
^
|
||||
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
|
||||
""::class.isInstance(42)
|
||||
^
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: isInstance
|
||||
""::class.isInstance(42)
|
||||
compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses
|
||||
""::class.sealedSubclasses
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
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
|
||||
typealias Unused = String
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
COMPILATION_ERROR
|
||||
|
||||
+2
-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
|
||||
import test.Str
|
||||
^
|
||||
@@ -13,4 +14,4 @@ compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCo
|
||||
compiler/testData/compileKotlinAgainstCustomBinaries/typeAliasesAreInvisibleInCompatibilityMode/main.kt:7:23: error: unresolved reference: Nested
|
||||
nested: Klass.Nested
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -3,9 +3,9 @@ Buildfile: [TestData]/build.xml
|
||||
|
||||
build:
|
||||
[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] class Derived : Base()
|
||||
[kotlinc] ^
|
||||
[kotlinc] [TestData]/main.kt:2:5: error: members are not allowed in annotation class
|
||||
[kotlinc] class Nested
|
||||
[kotlinc] ^
|
||||
|
||||
ERR:
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<target name="build">
|
||||
<kotlinc src="${test.data}/main.kt" output="${temp}/hello.jar">
|
||||
<compilerarg line="-language-version 1.0"/>
|
||||
<compilerarg line="-language-version 1.2"/>
|
||||
</kotlinc>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
sealed class Base
|
||||
|
||||
class Derived : Base()
|
||||
annotation class Outer {
|
||||
class Nested
|
||||
}
|
||||
|
||||
@@ -151,6 +151,16 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
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")
|
||||
public void testDiagnosticsOrder() throws Exception {
|
||||
runTest("compiler/testData/cli/jvm/diagnosticsOrder.args");
|
||||
|
||||
+1
-1
@@ -251,7 +251,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
||||
fun testPreReleaseCompilerAgainstPreReleaseLibraryStableLanguageVersion() {
|
||||
withPreRelease(true) {
|
||||
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(
|
||||
"source.kt", tmpdir, listOf(library), K2JVMCompiler(),
|
||||
listOf("-language-version", someStableReleasedVersion.versionString)
|
||||
|
||||
@@ -213,6 +213,9 @@ enum class LanguageVersion(val major: Int, val minor: Int) : DescriptionAware {
|
||||
fun fromFullVersionString(str: String) =
|
||||
str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null }
|
||||
|
||||
@JvmField
|
||||
val FIRST_SUPPORTED = KOTLIN_1_2
|
||||
|
||||
@JvmField
|
||||
val LATEST_STABLE = KOTLIN_1_3
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user