From 994c2229df32cbfdb41ab060e6f33440f75f2d2d Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Wed, 24 May 2023 22:15:41 +0200 Subject: [PATCH] [FIR] Report UNSUPPORTED_FEATURE for expect/actual members if MPP is disabled Always enable MultiPlatformProjects for K2MetadataCompilerArguments ^KT-57243 Fixed --- .../common/arguments/CommonCompilerArguments.kt | 4 ++++ .../arguments/K2MetadataCompilerArguments.kt | 6 ++++++ .../RedundantModalityModifierChecker.kt | 2 ++ .../testData/resolve/multifile/simpleStarImport.kt | 2 ++ .../testData/resolve/problems/expectConstructor.kt | 2 ++ .../FirExpectActualDeclarationChecker.kt | 14 +++++++++++++- compiler/testData/cli/metadata/hmppModules.args | 1 - compiler/testData/cli/metadata/hmppModules.out | 9 --------- .../inheritorOfExpectSealedClassWithFir.args | 9 +++++++-- .../inheritorOfExpectSealedClassWithFir.out | 3 ++- .../noMultiplatformProjects.fir.kt | 7 ------- .../sourceCompatibility/noMultiplatformProjects.kt | 7 ++++++- 12 files changed, 44 insertions(+), 22 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index eeb28c2093c..faba806328e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -868,8 +868,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() { if (internalArguments.isNotEmpty()) { configureLanguageFeaturesFromInternalArgs(collector) } + + configureExtraLanguageFeatures(this) } + protected open fun configureExtraLanguageFeatures(map: HashMap) {} + private fun HashMap.configureLanguageFeaturesFromInternalArgs(collector: MessageCollector) { val featuresThatForcePreReleaseBinaries = mutableListOf() val disabledFeaturesFromUnsupportedVersions = mutableListOf() diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt index 1f7bd8b31d9..da2980b5368 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2MetadataCompilerArguments.kt @@ -16,6 +16,8 @@ package org.jetbrains.kotlin.cli.common.arguments +import org.jetbrains.kotlin.config.LanguageFeature + class K2MetadataCompilerArguments : CommonCompilerArguments() { companion object { @JvmStatic private val serialVersionUID = 0L @@ -80,4 +82,8 @@ class K2MetadataCompilerArguments : CommonCompilerArguments() { } override fun copyOf(): Freezable = copyK2MetadataCompilerArguments(this, K2MetadataCompilerArguments()) + + override fun configureExtraLanguageFeatures(map: HashMap) { + map[LanguageFeature.MultiPlatformProjects] = LanguageFeature.State.ENABLED + } } diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt index 08b739cc5db..751373621f8 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantModalityModifierChecker.kt @@ -1,3 +1,5 @@ +// LANGUAGE: +MultiPlatformProjects + object O { fun foo() {} } diff --git a/compiler/fir/analysis-tests/testData/resolve/multifile/simpleStarImport.kt b/compiler/fir/analysis-tests/testData/resolve/multifile/simpleStarImport.kt index 9531ede6c8d..ef5468802e1 100644 --- a/compiler/fir/analysis-tests/testData/resolve/multifile/simpleStarImport.kt +++ b/compiler/fir/analysis-tests/testData/resolve/multifile/simpleStarImport.kt @@ -1,3 +1,5 @@ +// LANGUAGE: +MultiPlatformProjects + // FILE: B.kt package b.d diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/expectConstructor.kt b/compiler/fir/analysis-tests/testData/resolve/problems/expectConstructor.kt index 8293c2763d0..bd221bad8f4 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/expectConstructor.kt +++ b/compiler/fir/analysis-tests/testData/resolve/problems/expectConstructor.kt @@ -1,3 +1,5 @@ +// LANGUAGE: +MultiPlatformProjects + open class Base(v: String) expect class Derived(v: String) : Base diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt index 37da4ad2810..ceb919d2d3f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext @@ -35,8 +36,19 @@ import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull @Suppress("DuplicatedCode") object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() { override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { - if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)) return if (declaration !is FirMemberDeclaration) return + if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)) { + if ((declaration.isExpect || declaration.isActual) && context.containingDeclarations.lastOrNull() is FirFile) { + reporter.reportOn( + declaration.source, + FirErrors.UNSUPPORTED_FEATURE, + LanguageFeature.MultiPlatformProjects to context.session.languageVersionSettings, + context, + positioningStrategy = SourceElementPositioningStrategies.EXPECT_ACTUAL_MODIFIER + ) + } + return + } if (declaration.isExpect) { checkExpectDeclarationModifiers(declaration, context, reporter) } diff --git a/compiler/testData/cli/metadata/hmppModules.args b/compiler/testData/cli/metadata/hmppModules.args index 7599069f856..6de42540016 100644 --- a/compiler/testData/cli/metadata/hmppModules.args +++ b/compiler/testData/cli/metadata/hmppModules.args @@ -5,7 +5,6 @@ $TESTDATA_DIR$/../jvm/hmpp/src/c.kt $TEMP_DIR$ -language-version 2.0 --XXLanguage\:+MultiPlatformProjects -Xfragments=a,b,c -Xfragment-sources=a\:$TESTDATA_DIR$/../jvm/hmpp/src/a.kt -Xfragment-sources=b\:$TESTDATA_DIR$/../jvm/hmpp/src/b.kt diff --git a/compiler/testData/cli/metadata/hmppModules.out b/compiler/testData/cli/metadata/hmppModules.out index f96d1e5daf3..2e4ada349a5 100644 --- a/compiler/testData/cli/metadata/hmppModules.out +++ b/compiler/testData/cli/metadata/hmppModules.out @@ -1,12 +1,3 @@ -warning: ATTENTION! -This build uses unsafe internal compiler arguments: - --XXLanguage:+MultiPlatformProjects - -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 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features error: HMPP module structure should not be passed during metadata compilation. Please remove `-Xfragments` and related flags COMPILATION_ERROR diff --git a/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.args b/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.args index 27f1123c813..74e779622ee 100644 --- a/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.args +++ b/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.args @@ -3,6 +3,11 @@ $TESTDATA_DIR$/inheritorOfExpectSealedClass/common-2.kt $TESTDATA_DIR$/inheritorOfExpectSealedClass/common-3.kt -d $TEMP_DIR$ --Xcommon-sources=$TESTDATA_DIR$/inheritorOfExpectSealedClass/common-1.kt,$TESTDATA_DIR$/inheritorOfExpectSealedClass/common-2.kt -language-version -2.0 \ No newline at end of file +2.0 +-Xfragments=a,b,c +-Xfragment-sources=a\:$TESTDATA_DIR$/inheritorOfExpectSealedClass/common-1.kt +-Xfragment-sources=b\:$TESTDATA_DIR$/inheritorOfExpectSealedClass/common-2.kt +-Xfragment-sources=c\:$TESTDATA_DIR$/inheritorOfExpectSealedClass/common-3.kt +-Xfragment-refines=b\:a +-Xfragment-refines=c\:b \ No newline at end of file diff --git a/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.out b/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.out index 86ca0241885..2e4ada349a5 100644 --- a/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.out +++ b/compiler/testData/cli/metadata/inheritorOfExpectSealedClassWithFir.out @@ -1,2 +1,3 @@ warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features -OK +error: HMPP module structure should not be passed during metadata compilation. Please remove `-Xfragments` and related flags +COMPILATION_ERROR diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt deleted file mode 100644 index e5beb009775..00000000000 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -expect fun foo1() -expect val bar1 = 42 -expect class Baz1 - -actual fun foo2() = 42 -actual val bar2: Int -actual interface Baz2 diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.kt index e9cfa4b3549..c7f45df8844 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noMultiplatformProjects.kt @@ -1,6 +1,11 @@ +// FIR_IDENTICAL expect fun foo1() expect val bar1 = 42 -expect class Baz1 +expect class Baz1 { + fun foo() + + class Baz12 +} actual fun foo2() = 42 actual val bar2: Int