KMP: Put "prohibit expect/actual tailrec/external" under the flag

^KT-61668 Fixed

Review: https://jetbrains.team/p/kt/reviews/12062/timeline
This commit is contained in:
Nikita Bobko
2023-09-05 16:15:47 +02:00
committed by Space Team
parent 172c04c96a
commit e742d43ee0
8 changed files with 75 additions and 5 deletions
@@ -145,6 +145,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
runTest("compiler/testData/diagnostics/tests/multiplatform/expectExternal.kt");
}
@Test
@TestMetadata("expectExternal_oldLanguageVersion.kt")
public void testExpectExternal_oldLanguageVersion() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectExternal_oldLanguageVersion.kt");
}
@Test
@TestMetadata("expectInterfaceApplicability.kt")
public void testExpectInterfaceApplicability() throws Exception {
@@ -175,6 +181,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
runTest("compiler/testData/diagnostics/tests/multiplatform/expectTailrec.kt");
}
@Test
@TestMetadata("expectTailrec_oldLanguageVersion.kt")
public void testExpectTailrec_oldLanguageVersion() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectTailrec_oldLanguageVersion.kt");
}
@Test
@TestMetadata("headerFunInNonHeaderClass.kt")
public void testHeaderFunInNonHeaderClass() throws Exception {
@@ -145,6 +145,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/tests/multiplatform/expectExternal.kt");
}
@Test
@TestMetadata("expectExternal_oldLanguageVersion.kt")
public void testExpectExternal_oldLanguageVersion() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectExternal_oldLanguageVersion.kt");
}
@Test
@TestMetadata("expectInterfaceApplicability.kt")
public void testExpectInterfaceApplicability() throws Exception {
@@ -175,6 +181,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/tests/multiplatform/expectTailrec.kt");
}
@Test
@TestMetadata("expectTailrec_oldLanguageVersion.kt")
public void testExpectTailrec_oldLanguageVersion() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectTailrec_oldLanguageVersion.kt");
}
@Test
@TestMetadata("headerFunInNonHeaderClass.kt")
public void testHeaderFunInNonHeaderClass() throws Exception {
@@ -76,7 +76,9 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
if (declaration is FirProperty) {
checkExpectPropertyAccessorsModifiers(declaration, context, reporter)
}
if (declaration is FirFunction && declaration.isTailRec) {
if (context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions) &&
declaration is FirFunction && declaration.isTailRec
) {
reporter.reportOn(declaration.source, FirErrors.EXPECTED_TAILREC_FUNCTION, context)
}
}
@@ -108,7 +110,9 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() {
context: CheckerContext,
reporter: DiagnosticReporter,
) {
if (declaration.isExternal) {
if (context.languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions) &&
declaration.isExternal
) {
reporter.reportOn(declaration.source, FirErrors.EXPECTED_EXTERNAL_DECLARATION, context)
}
}
@@ -637,7 +637,7 @@ class DeclarationsChecker(
}
checkExpectDeclarationHasNoExternalModifier(declaration)
if (declaration is KtFunction) {
if (declaration is KtFunction && languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) {
declaration.modifierList?.getModifier(KtTokens.TAILREC_KEYWORD)?.let {
trace.report(EXPECTED_TAILREC_FUNCTION.on(it))
}
@@ -645,8 +645,10 @@ class DeclarationsChecker(
}
private fun checkExpectDeclarationHasNoExternalModifier(declaration: KtDeclaration) {
declaration.modifierList?.getModifier(KtTokens.EXTERNAL_KEYWORD)?.let {
trace.report(EXPECTED_EXTERNAL_DECLARATION.on(it))
if (languageVersionSettings.supportsFeature(LanguageFeature.MultiplatformRestrictions)) {
declaration.modifierList?.getModifier(KtTokens.EXTERNAL_KEYWORD)?.let {
trace.report(EXPECTED_EXTERNAL_DECLARATION.on(it))
}
}
}
@@ -0,0 +1,10 @@
// FIR_IDENTICAL
// LANGUAGE: -MultiplatformRestrictions
// MODULE: m1-common
// FILE: common.kt
expect external fun foo()
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual external fun foo()
@@ -0,0 +1,9 @@
// LANGUAGE: -MultiplatformRestrictions
// MODULE: m1-common
// FILE: common.kt
expect <!NO_TAIL_CALLS_FOUND!>tailrec<!> fun foo(p: Int): Int
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual tailrec fun foo(p: Int): Int = foo(p)
@@ -0,0 +1,9 @@
// LANGUAGE: -MultiplatformRestrictions
// MODULE: m1-common
// FILE: common.kt
expect tailrec fun foo(p: Int): Int
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual tailrec fun foo(p: Int): Int = foo(p)
@@ -23140,6 +23140,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectExternal.kt");
}
@Test
@TestMetadata("expectExternal_oldLanguageVersion.kt")
public void testExpectExternal_oldLanguageVersion() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectExternal_oldLanguageVersion.kt");
}
@Test
@TestMetadata("expectInterfaceApplicability.kt")
public void testExpectInterfaceApplicability() throws Exception {
@@ -23170,6 +23176,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectTailrec.kt");
}
@Test
@TestMetadata("expectTailrec_oldLanguageVersion.kt")
public void testExpectTailrec_oldLanguageVersion() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/expectTailrec_oldLanguageVersion.kt");
}
@Test
@TestMetadata("headerFunInNonHeaderClass.kt")
public void testHeaderFunInNonHeaderClass() throws Exception {