diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt index fdb6b133c63..e4aa7436727 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/builders/LanguageVersionSettingsBuilder.kt @@ -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( diff --git a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt index 46c8129cd32..ec7e6aa9751 100644 --- a/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt +++ b/compiler/test-infrastructure/tests/org/jetbrains/kotlin/test/directives/LanguageSettingsDirectives.kt @@ -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( diff --git a/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple-lang-ver-2.1.kt b/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple-lang-ver-2.1.kt index 4fce8065553..356bab2750f 100644 --- a/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple-lang-ver-2.1.kt +++ b/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple-lang-ver-2.1.kt @@ -1,4 +1,5 @@ // API_VERSION: 2.0 +// ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING // LANGUAGE_VERSION: 2.1 package test diff --git a/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple.kt b/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple.kt index f5982ca1d07..ce07dd8ddfc 100644 --- a/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple.kt +++ b/plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple.kt @@ -1,4 +1,5 @@ // API_VERSION: 2.0 +// ALLOW_DANGEROUS_LANGUAGE_VERSION_TESTING // LANGUAGE_VERSION: 2.0 package test