diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 38b59a7106a..c27d2d972fd 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -28058,6 +28058,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt"); } + @Test + @TestMetadata("otherModuleInheritance.kt") + public void testOtherModuleInheritance() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt"); + } + @Test @TestMetadata("protected.kt") public void testProtected() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index db9489ebd61..0f7855d9263 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -28058,6 +28058,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt"); } + @Test + @TestMetadata("otherModuleInheritance.kt") + public void testOtherModuleInheritance() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt"); + } + @Test @TestMetadata("protected.kt") public void testProtected() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt index 60a42c16810..aad0a84a86c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/VariableStorage.kt @@ -15,6 +15,8 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression +import org.jetbrains.kotlin.fir.originalIfFakeOverride +import org.jetbrains.kotlin.fir.originalOrSelf import org.jetbrains.kotlin.fir.references.FirThisReference import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.toSymbol @@ -184,7 +186,7 @@ class VariableStorage(private val session: FirSession) { property.isVar -> PropertyStability.MUTABLE_PROPERTY property.receiverTypeRef != null -> PropertyStability.PROPERTY_WITH_GETTER property.getter.let { it != null && it !is FirDefaultPropertyAccessor } -> PropertyStability.PROPERTY_WITH_GETTER - property.moduleData.session != session -> PropertyStability.ALIEN_PUBLIC_PROPERTY + property.originalOrSelf().moduleData.session != session -> PropertyStability.ALIEN_PUBLIC_PROPERTY property.modality != Modality.FINAL -> { val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccess)?.dispatchReceiver ?: return null val receiverType = dispatchReceiver.typeRef.coneTypeSafe()?.fullyExpandedType(session) ?: return null diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.fir.kt new file mode 100644 index 00000000000..d421d8e7e6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.fir.kt @@ -0,0 +1,25 @@ +// MODULE: m1 +// FILE: A.kt + +open class Base(val x: Any) +open class Generic(val y: T) + +// MODULE: m2(m1) +// FILE: B.kt + +class Derived : Base("123") { + fun foo() { + if (x is String) { + x.length // impossible since `x` is in another module. FE1.0 allows this due to KT-47225 + } + } +} + +class MyGeneric : Generic(42) { + private fun baz(arg: Int) {} + fun bar() { + if (y is Int) { + baz(y) // impossible since `y` is in another module. FE1.0 allows this due to KT-47225 + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt new file mode 100644 index 00000000000..5c115f269db --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt @@ -0,0 +1,25 @@ +// MODULE: m1 +// FILE: A.kt + +open class Base(val x: Any) +open class Generic(val y: T) + +// MODULE: m2(m1) +// FILE: B.kt + +class Derived : Base("123") { + fun foo() { + if (x is String) { + x.length // impossible since `x` is in another module. FE1.0 allows this due to KT-47225 + } + } +} + +class MyGeneric : Generic(42) { + private fun baz(arg: Int) {} + fun bar() { + if (y is Int) { + baz(y) // impossible since `y` is in another module. FE1.0 allows this due to KT-47225 + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.txt b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.txt new file mode 100644 index 00000000000..371750913dc --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.txt @@ -0,0 +1,40 @@ +// -- Module: -- +package + +public open class Base { + public constructor Base(/*0*/ x: kotlin.Any) + public final val x: kotlin.Any + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Generic { + public constructor Generic(/*0*/ y: T) + public final val y: T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +// -- Module: -- +package + +public final class Derived : Base { + public constructor Derived() + public final override /*1*/ /*fake_override*/ val x: kotlin.Any + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class MyGeneric : Generic { + public constructor MyGeneric() + public final override /*1*/ /*fake_override*/ val y: kotlin.Number + public final fun bar(): kotlin.Unit + private final fun baz(/*0*/ arg: kotlin.Int): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt deleted file mode 100644 index f8279f4fec2..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun foo1(p: Pair): Int { - if (p.first != null) return p.first!! - return p.second -} - -fun foo2(p: Pair): Int { - if (p.first != null) return p.first - return p.second -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.kt index 9c891674d7e..20d8989fb08 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt10001.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun foo1(p: Pair): Int { if (p.first != null) return p.first!! return p.second 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 aca5cddbf6f..e7e05fd5a38 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 @@ -28148,6 +28148,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt"); } + @Test + @TestMetadata("otherModuleInheritance.kt") + public void testOtherModuleInheritance() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt"); + } + @Test @TestMetadata("protected.kt") public void testProtected() throws Exception { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/40.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/40.fir.kt index cb6c1dd9511..d8d80673ed2 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/40.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/40.fir.kt @@ -9,7 +9,7 @@ fun case_1(x: Pair<*, *>) { if (x.first !is String) return x.first - x.first.length + x.first.length } /* @@ -19,5 +19,5 @@ fun case_1(x: Pair<*, *>) { fun case_2(x: Pair<*, *>) { if (x.first !is String?) throw Exception() x.first - x.first?.length + x.first?.length } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 67d2a3bd7ce..66166e37bb3 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -28058,6 +28058,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt"); } + @Test + @TestMetadata("otherModuleInheritance.kt") + public void testOtherModuleInheritance() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt"); + } + @Test @TestMetadata("protected.kt") public void testProtected() throws Exception {