From 888bf801e2a3abccba3f310d69ee4f2904c1a33a Mon Sep 17 00:00:00 2001 From: "Evgeniy.Zhelenskiy" Date: Mon, 6 Mar 2023 20:40:03 +0100 Subject: [PATCH] [FIR] Forbid @JvmInline with inline modifier Signed-off-by: Evgeniy.Zhelenskiy #KT-1179 --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 +++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 +++ .../FirJvmInlineApplicabilityChecker.kt | 3 +- .../valueClasses/inlineKeywordForMfvc.kt | 37 +++++++++++++++++++ .../jvmInlineApplicability.fir.kt | 2 +- .../test/runners/DiagnosticTestGenerated.java | 6 +++ 7 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 7083799bf8e..53435a1c2db 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -34376,6 +34376,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/valueClasses/inefficientEqualsOverridingInMfvc.kt"); } + @Test + @TestMetadata("inlineKeywordForMfvc.kt") + public void testInlineKeywordForMfvc() throws Exception { + runTest("compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt"); + } + @Test @TestMetadata("jvmInlineApplicability.kt") public void testJvmInlineApplicability() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 9c8e33d515a..399cac00637 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -34376,6 +34376,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/valueClasses/inefficientEqualsOverridingInMfvc.kt"); } + @Test + @TestMetadata("inlineKeywordForMfvc.kt") + public void testInlineKeywordForMfvc() throws Exception { + runTest("compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt"); + } + @Test @TestMetadata("jvmInlineApplicability.kt") public void testJvmInlineApplicability() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 5ca95d6b070..f93b1d9099d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -34472,6 +34472,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/valueClasses/inefficientEqualsOverridingInMfvc.kt"); } + @Test + @TestMetadata("inlineKeywordForMfvc.kt") + public void testInlineKeywordForMfvc() throws Exception { + runTest("compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt"); + } + @Test @TestMetadata("jvmInlineApplicability.kt") public void testJvmInlineApplicability() throws Exception { diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt index f7949ab3c38..4acaac267d5 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirJvmInlineApplicabilityChecker.kt @@ -21,7 +21,8 @@ import org.jetbrains.kotlin.resolve.JVM_INLINE_ANNOTATION_CLASS_ID object FirJvmInlineApplicabilityChecker : FirRegularClassChecker() { override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) { val annotation = declaration.getAnnotationByClassId(JVM_INLINE_ANNOTATION_CLASS_ID, context.session) - if (annotation != null && !declaration.isInline) { + if (annotation != null && !(declaration.isInline && declaration.getModifier(KtTokens.VALUE_KEYWORD) != null)) { + // only report if value keyword does not exist, this includes the deprecated inline class syntax reporter.reportOn(annotation.source, FirJvmErrors.JVM_INLINE_WITHOUT_VALUE_CLASS, context) } else if (annotation == null && declaration.isInline && !declaration.isExpect) { // only report if value keyword exists, this ignores the deprecated inline class syntax diff --git a/compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt b/compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt new file mode 100644 index 00000000000..b02db71650f --- /dev/null +++ b/compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt @@ -0,0 +1,37 @@ +// FIR_IDENTICAL +// WITH_STDLIB +// LANGUAGE: +ValueClasses + +@file:Suppress("INLINE_CLASS_DEPRECATED") + +inline class A1(val x: Int) + +@JvmInline +value class A2(val x: Int) + +@JvmInline +inline class A3(val x: Int) + +value class A4(val x: Int) + + +inline class B1(val x: Int, val y: Int) + +@JvmInline +value class B2(val x: Int, val y: Int) + +@JvmInline +inline class B3(val x: Int, val y: Int) + +value class B4(val x: Int, val y: Int) + + +inline class C1(val x: B2) + +@JvmInline +value class C2(val x: B2) + +@JvmInline +inline class C3(val x: B2) + +value class C4(val x: B2) diff --git a/compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.fir.kt b/compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.fir.kt index b155535e784..7ce4a0d812c 100644 --- a/compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.fir.kt +++ b/compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.fir.kt @@ -6,7 +6,7 @@ package kotlin.jvm annotation class JvmInline -@JvmInline +@JvmInline inline class IC(val a: Any) @JvmInline diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index f855b393b02..36c51778ebe 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -34472,6 +34472,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/valueClasses/inefficientEqualsOverridingInMfvc.kt"); } + @Test + @TestMetadata("inlineKeywordForMfvc.kt") + public void testInlineKeywordForMfvc() throws Exception { + runTest("compiler/testData/diagnostics/tests/valueClasses/inlineKeywordForMfvc.kt"); + } + @Test @TestMetadata("jvmInlineApplicability.kt") public void testJvmInlineApplicability() throws Exception {