[FIR] Report redeclaration across KMP source sets
^KT-57585 Fixed Related tests: - MultiPlatformIntegrationTestGenerated.testSimpleNoImplKeywordOnTopLevelFunction - MultiPlatformIntegrationTestGenerated.testWeakIncompatibilityWithoutActualModifier - FirPsiJsKlibDiagnosticsTestGenerated.testSignatureClash_MPP - LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated$ResolveWithStdlib$MultiModule.testFakeOverrides - DiagnosticCompilerTestFE10TestdataTestGenerated$Tests$Multiplatform: - LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated$Tests$Multiplatform - FirOldFrontendMPPDiagnosticsWithPsiTestGenerated - FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated - FirLibraryModuleDeclarationResolveTestGenerated.testDataClass - org.jetbrains.kotlin.idea.k2.highlighting.K2HighlightingMetaInfoTestGenerated$Diagnostics.testDataClassFromLibrary - org.jetbrains.fir.uast.test.FirLightClassBehaviorTest.testContainingFile - org.jetbrains.fir.uast.test.FirLightClassBehaviorTest.testAnnotationParameterReference - org.jetbrains.uast.test.kotlin.org.jetbrains.uast.test.kotlin.comparison.FE1LightClassBehaviorTest.testContainingFile
This commit is contained in:
+12
@@ -26681,6 +26681,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/ambiguousActuals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclaration.kt")
|
||||
public void testHmppRedeclaration() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclarationWithExpectActualPair.kt")
|
||||
public void testHmppRedeclarationWithExpectActualPair() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclarationWithExpectActualPair.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateActualHasAdditionalSupertypes.kt")
|
||||
public void testIntermediateActualHasAdditionalSupertypes() {
|
||||
|
||||
+12
@@ -26681,6 +26681,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/ambiguousActuals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclaration.kt")
|
||||
public void testHmppRedeclaration() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclarationWithExpectActualPair.kt")
|
||||
public void testHmppRedeclarationWithExpectActualPair() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclarationWithExpectActualPair.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateActualHasAdditionalSupertypes.kt")
|
||||
public void testIntermediateActualHasAdditionalSupertypes() {
|
||||
|
||||
+12
@@ -1740,6 +1740,18 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/ambiguousActuals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclaration.kt")
|
||||
public void testHmppRedeclaration() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclarationWithExpectActualPair.kt")
|
||||
public void testHmppRedeclarationWithExpectActualPair() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclarationWithExpectActualPair.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateActualHasAdditionalSupertypes.kt")
|
||||
public void testIntermediateActualHasAdditionalSupertypes() {
|
||||
|
||||
+12
@@ -1740,6 +1740,18 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/ambiguousActuals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclaration.kt")
|
||||
public void testHmppRedeclaration() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclarationWithExpectActualPair.kt")
|
||||
public void testHmppRedeclarationWithExpectActualPair() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclarationWithExpectActualPair.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateActualHasAdditionalSupertypes.kt")
|
||||
public void testIntermediateActualHasAdditionalSupertypes() {
|
||||
|
||||
+9
-2
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirNameConflictsTr
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isEffectivelyFinal
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl.Companion.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedDeclarationStatusImpl.Companion.DEFAULT_STATUS_FOR_SUSPEND_MAIN_FUNCTION
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.modifiersRepresentation
|
||||
@@ -439,6 +438,10 @@ private fun FirClassLikeSymbol<*>.expandedClassWithConstructorsScope(context: Ch
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldCheckForMultiplatformRedeclaration(dependency: FirBasedSymbol<*>, dependent: FirBasedSymbol<*>): Boolean =
|
||||
dependent.moduleData.allDependsOnDependencies.contains(dependency.moduleData) &&
|
||||
dependency.resolvedStatus?.isExpect != true // ACTUAL_MISSING takes care of this case
|
||||
|
||||
private fun FirDeclarationCollector<FirBasedSymbol<*>>.collectTopLevelConflict(
|
||||
declaration: FirBasedSymbol<*>,
|
||||
declarationPresentation: String,
|
||||
@@ -448,7 +451,11 @@ private fun FirDeclarationCollector<FirBasedSymbol<*>>.collectTopLevelConflict(
|
||||
conflictingFile: FirFile? = null,
|
||||
) {
|
||||
conflictingSymbol.lazyResolveToPhase(FirResolvePhase.STATUS)
|
||||
if (conflictingSymbol == declaration || declaration.moduleData != conflictingSymbol.moduleData) return
|
||||
if (conflictingSymbol == declaration) return
|
||||
if (
|
||||
declaration.moduleData != conflictingSymbol.moduleData &&
|
||||
!shouldCheckForMultiplatformRedeclaration(declaration, conflictingSymbol)
|
||||
) return
|
||||
val actualConflictingPresentation = conflictingPresentation ?: FirRedeclarationPresenter.represent(conflictingSymbol)
|
||||
if (actualConflictingPresentation != declarationPresentation) return
|
||||
val actualConflictingFile =
|
||||
|
||||
+6
@@ -1,8 +1,14 @@
|
||||
Module: common
|
||||
/common.kt:8:1: error: Conflicting overloads:
|
||||
fun foo(): Int
|
||||
|
||||
/common.kt:8:1: error: Platform declaration clash: The following functions have the same IR signature (/foo|foo(){}[0]):
|
||||
fun foo(): kotlin.Int defined in root package
|
||||
fun foo(): kotlin.String defined in root package
|
||||
|
||||
/common.kt:11:1: error: Conflicting overloads:
|
||||
fun bar(x: B): Int
|
||||
|
||||
/common.kt:11:1: error: Platform declaration clash: The following functions have the same IR signature (/bar|bar(B){}[0]):
|
||||
fun bar(x: B): kotlin.Int defined in root package
|
||||
fun bar(x: B): kotlin.Int defined in root package
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
|
||||
// MODULE: common
|
||||
// FILE: common.kt
|
||||
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>fun foo(): String = ""<!>
|
||||
<!CONFLICTING_KLIB_SIGNATURES_ERROR!><!CONFLICTING_OVERLOADS!>fun foo(): String<!> = ""<!>
|
||||
|
||||
expect class A
|
||||
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>fun bar(x: A): Int = 2<!>
|
||||
<!CONFLICTING_KLIB_SIGNATURES_ERROR!><!CONFLICTING_OVERLOADS!>fun bar(x: A): Int<!> = 2<!>
|
||||
|
||||
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>@Suppress("REDECLARATION")
|
||||
val param = 0<!>
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
open class A {
|
||||
open class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>A<!> {
|
||||
open fun foo(): String = "Fail"
|
||||
}
|
||||
expect class C1() : A
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
open class A {
|
||||
open fun foo(): String = "Fail"
|
||||
}
|
||||
expect class C1() : A
|
||||
expect class C2() : A
|
||||
|
||||
// MODULE: m2-jvm()()(m1-common)
|
||||
// FILE: A_J.java
|
||||
public class A_J {}
|
||||
|
||||
// FILE: B_J.java
|
||||
public class B_J extends A_J {
|
||||
public String foo() { return "O"; }
|
||||
}
|
||||
|
||||
// FILE: C2_J.java
|
||||
public class C2_J extends B_J {
|
||||
public String foo() { return "K"; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
actual typealias <!ACTUAL_WITHOUT_EXPECT!>A<!> = A_J
|
||||
|
||||
// Indirect subtyping is allowed in K2 KT-59356
|
||||
actual class C1 : B_J()
|
||||
actual typealias C2 = C2_J
|
||||
compiler/testData/diagnostics/tests/multiplatform/actualWithoutExpectWhenExpectIsFakeOverride.fir.kt
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
fun foo() {}
|
||||
class Foo
|
||||
<!CONFLICTING_OVERLOADS!>fun foo()<!> {}
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>Foo<!>
|
||||
|
||||
open class Base {
|
||||
open fun foo() {}
|
||||
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
fun foo() {}
|
||||
class Foo
|
||||
|
||||
open class Base {
|
||||
open fun foo() {}
|
||||
}
|
||||
expect class Bar : Base {
|
||||
}
|
||||
|
||||
expect open class ExpectBase {
|
||||
open fun foo()
|
||||
}
|
||||
expect class Baz : ExpectBase
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
actual fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
|
||||
actual class <!ACTUAL_WITHOUT_EXPECT!>Foo<!>
|
||||
|
||||
actual class Bar : Base() {
|
||||
actual override fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
|
||||
}
|
||||
|
||||
actual open class ExpectBase {
|
||||
actual open fun foo() {}
|
||||
}
|
||||
actual class Baz : ExpectBase() {
|
||||
actual override fun <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
expect fun <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>main<!>()
|
||||
|
||||
// FILE: common2.kt
|
||||
actual fun <!ACTUAL_WITHOUT_EXPECT, EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>main<!>() {}
|
||||
<!CONFLICTING_OVERLOADS!>actual fun <!ACTUAL_WITHOUT_EXPECT!>main<!>()<!> {}
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
expect fun <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>main<!>()
|
||||
|
||||
// FILE: common2.kt
|
||||
actual fun <!ACTUAL_WITHOUT_EXPECT, EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>main<!>() {}
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
expect fun <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>main<!>()
|
||||
|
||||
// FILE: jvm2.kt
|
||||
actual fun <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>main<!>() {}
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
actual fun foo() {}
|
||||
<!CONFLICTING_OVERLOADS!>actual fun foo()<!> {}
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
actual fun foo() {}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>A<!>
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>C<!>
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
class A
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>B<!>
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
|
||||
class B
|
||||
|
||||
class C
|
||||
@@ -0,0 +1,19 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION{COMMON}, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>A<!>
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>C<!>
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>A<!>
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>B<!>
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>B<!>
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>C<!>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
class A
|
||||
|
||||
class C
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
class A
|
||||
|
||||
class B
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
|
||||
class B
|
||||
|
||||
class C
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
expect class A
|
||||
|
||||
expect class B
|
||||
|
||||
class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>C<!>
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
actual class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>A<!>
|
||||
|
||||
class <!ACTUAL_MISSING, PACKAGE_OR_CLASSIFIER_REDECLARATION!>B<!>
|
||||
|
||||
expect class C
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
|
||||
class A
|
||||
|
||||
actual class <!ACTUAL_WITHOUT_EXPECT!>B<!>
|
||||
|
||||
actual class C
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
expect <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE{COMMON}!>class <!AMBIGUOUS_ACTUALS{JVM}, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>A<!><!>
|
||||
|
||||
expect <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE{COMMON}!>class <!AMBIGUOUS_ACTUALS{JVM}, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>B<!><!>
|
||||
|
||||
<!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE{COMMON}!>class <!ACTUAL_MISSING{JVM}, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>C<!><!>
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
actual <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>class <!PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>A<!><!>
|
||||
|
||||
<!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>class <!ACTUAL_MISSING{JVM}, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>B<!><!>
|
||||
|
||||
expect <!EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE!>class <!AMBIGUOUS_ACTUALS{JVM}, PACKAGE_OR_CLASSIFIER_REDECLARATION{JVM}!>C<!><!>
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
|
||||
class <!ACTUAL_MISSING, PACKAGE_OR_CLASSIFIER_REDECLARATION!>A<!>
|
||||
|
||||
actual class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>B<!>
|
||||
|
||||
actual class <!PACKAGE_OR_CLASSIFIER_REDECLARATION!>C<!>
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
expect class A
|
||||
|
||||
expect class B
|
||||
|
||||
class C
|
||||
|
||||
// MODULE: intermediate()()(common)
|
||||
// TARGET_PLATFORM: Common
|
||||
|
||||
actual class A
|
||||
|
||||
class <!ACTUAL_MISSING!>B<!>
|
||||
|
||||
expect class C
|
||||
|
||||
// MODULE: main()()(common, intermediate)
|
||||
|
||||
class A
|
||||
|
||||
actual class <!ACTUAL_WITHOUT_EXPECT!>B<!>
|
||||
|
||||
actual class C
|
||||
Generated
+12
@@ -26681,6 +26681,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/ambiguousActuals.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclaration.kt")
|
||||
public void testHmppRedeclaration() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclaration.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("hmppRedeclarationWithExpectActualPair.kt")
|
||||
public void testHmppRedeclarationWithExpectActualPair() {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/hmpp/hmppRedeclarationWithExpectActualPair.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intermediateActualHasAdditionalSupertypes.kt")
|
||||
public void testIntermediateActualHasAdditionalSupertypes() {
|
||||
|
||||
Reference in New Issue
Block a user