diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 725024a531c..cdaa879604d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -35588,6 +35588,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/statics/protectedStaticAndInline.kt"); } + @Test + @TestMetadata("simpleStaticInJavaSuperChain.kt") + public void testSimpleStaticInJavaSuperChain() throws Exception { + runTest("compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt"); + } + @Test @TestMetadata("syntheticAccessor.kt") public void testSyntheticAccessor() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt index 38c4a2d54a9..27af854fac4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/BodyResolveComponents.kt @@ -180,7 +180,7 @@ fun SessionHolder.collectImplicitReceivers( throw IllegalArgumentException("Incorrect label & receiver owner: ${owner.javaClass}") } } - return ImplicitReceivers(implicitReceiverValue, implicitCompanionValues.asReversed()) + return ImplicitReceivers(implicitReceiverValue, implicitCompanionValues) } fun SessionHolder.collectTowerDataElementsForClass(owner: FirClass<*>, defaultType: ConeKotlinType): TowerElementsForClass { @@ -221,8 +221,8 @@ fun SessionHolder.collectTowerDataElementsForClass(owner: FirClass<*>, defaultTy owner.staticScope(this), companionReceiver, companionObject?.staticScope(this), - superClassesStaticsAndCompanionReceivers, - allImplicitCompanionValues + superClassesStaticsAndCompanionReceivers.asReversed(), + allImplicitCompanionValues.asReversed() ) } @@ -234,6 +234,8 @@ class TowerElementsForClass( val staticScope: FirScope?, val companionReceiver: ImplicitReceiverValue<*>?, val companionStaticScope: FirScope?, + // Ordered from inner scopes to outer scopes. val superClassesStaticsAndCompanionReceivers: List, + // Ordered from inner scopes to outer scopes. val implicitCompanionValues: List> ) diff --git a/compiler/testData/codegen/box/statics/protectedStatic2.kt b/compiler/testData/codegen/box/statics/protectedStatic2.kt index 1a8f42273bf..5b584a702a4 100644 --- a/compiler/testData/codegen/box/statics/protectedStatic2.kt +++ b/compiler/testData/codegen/box/statics/protectedStatic2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // FILE: Base.java diff --git a/compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt b/compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt new file mode 100644 index 00000000000..85f6fdfa2ed --- /dev/null +++ b/compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt @@ -0,0 +1,31 @@ +// TARGET_BACKEND: JVM + +// FILE: A.java + +public class A { + public static String s = "A.s: NOT OK"; + public static String f() { + return "A.f: NOT OK"; + } + + public static class B extends A { + public static String s = "OK"; + public static String f() { + return "OK"; + } + } +} + + +// FILE: Kotlin.kt + +class Kotlin: A.B() { + fun getS() = s + fun callF() = f() +} + +fun box(): String { + val kotlin = Kotlin() + if (kotlin.getS() != "OK") return "fail1" + return kotlin.callF() +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index fbd8c8d8487..739134dac50 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -35788,6 +35788,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/statics/protectedStaticAndInline.kt"); } + @Test + @TestMetadata("simpleStaticInJavaSuperChain.kt") + public void testSimpleStaticInJavaSuperChain() throws Exception { + runTest("compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt"); + } + @Test @TestMetadata("syntheticAccessor.kt") public void testSyntheticAccessor() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 4de1e3dfc00..306d9937b3d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -35588,6 +35588,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/statics/protectedStaticAndInline.kt"); } + @Test + @TestMetadata("simpleStaticInJavaSuperChain.kt") + public void testSimpleStaticInJavaSuperChain() throws Exception { + runTest("compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt"); + } + @Test @TestMetadata("syntheticAccessor.kt") public void testSyntheticAccessor() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a5448fe6e4d..355433bff8c 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -29277,6 +29277,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/statics/protectedStaticAndInline.kt"); } + @TestMetadata("simpleStaticInJavaSuperChain.kt") + public void testSimpleStaticInJavaSuperChain() throws Exception { + runTest("compiler/testData/codegen/box/statics/simpleStaticInJavaSuperChain.kt"); + } + @TestMetadata("syntheticAccessor.kt") public void testSyntheticAccessor() throws Exception { runTest("compiler/testData/codegen/box/statics/syntheticAccessor.kt");