Discourage the use of LANGUAGE_VERSION directive.
Pinning the language version is rarely the right thing to do. This changes makes it harder to do so by requiring an additional directive with a name that indicates to developers that they are likely doing something dangerous.
This commit is contained in:
+17
@@ -63,7 +63,24 @@ class LanguageVersionSettingsBuilder {
|
||||
this.languageVersion = languageVersion
|
||||
}
|
||||
val languageVersionDirective = directives.singleOrZeroValue(LanguageSettingsDirectives.LANGUAGE_VERSION)
|
||||
val allowDangerousLanguageVersionTesting =
|
||||
directives.contains(LanguageSettingsDirectives.ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING)
|
||||
if (languageVersionDirective != null) {
|
||||
if (!allowDangerousLanguageVersionTesting) {
|
||||
error(
|
||||
"""
|
||||
The LANGUAGE_VERSION directive is prone to limiting test to a specific language version,
|
||||
which will become obsolete at some point and the test won't check things like feature
|
||||
intersection with newer releases.
|
||||
|
||||
For language feature testing, use `// !LANGUAGE: [+-]FeatureName` directive instead,
|
||||
where FeatureName is an entry of the enum `LanguageFeature`
|
||||
|
||||
If you are really sure you need to pin language versions, use the LANGUAGE_VERSION
|
||||
directive in combination with the ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING directive.
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
languageVersion = languageVersionDirective
|
||||
if (languageVersion < LanguageVersion.fromVersionString(this.apiVersion.versionString)!!) {
|
||||
error(
|
||||
|
||||
+15
@@ -26,6 +26,21 @@ object LanguageSettingsDirectives : SimpleDirectivesContainer() {
|
||||
parser = this::parseLanguageVersion
|
||||
)
|
||||
|
||||
val ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING by directive(
|
||||
description = """
|
||||
Allows the use of the LANGUAGE_VERSION directive. However, before you use it, please
|
||||
make sure that you actually do need to pin language versions.
|
||||
|
||||
The LANGUAGE_VERSION directive is prone to limiting test to a specific language version,
|
||||
which will become obsolete at some point and the test won't check things like feature
|
||||
intersection with newer releases.
|
||||
|
||||
For language feature testing, use `// !LANGUAGE: [+-]FeatureName` directive instead,
|
||||
where FeatureName is an entry of the enum `LanguageFeature`
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
|
||||
// --------------------- Analysis Flags ---------------------
|
||||
|
||||
val OPT_IN by stringDirective(
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
// API_VERSION: 2.0
|
||||
// ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING
|
||||
// LANGUAGE_VERSION: 2.1
|
||||
package test
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// API_VERSION: 2.0
|
||||
// ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING
|
||||
// LANGUAGE_VERSION: 2.0
|
||||
package test
|
||||
|
||||
|
||||
Reference in New Issue
Block a user