From 238344758b1cceab14f0fccf29ed1300b8f04d9a Mon Sep 17 00:00:00 2001 From: Alexander Korepanov Date: Tue, 5 Sep 2023 16:29:37 +0200 Subject: [PATCH] [FIR] Fix the inability to retrieve an annotation argument Fix an issue where an inherited @JsName from another module was not accessible in a child class. The issue can only be reproduced in the codegen box tests and cannot be reproduced in the FIR FE checker tests. --- .../fir/analysis/checkers/FirHelpers.kt | 2 +- .../js/test/fir/FirJsBoxTestGenerated.java | 6 ++++++ .../js/test/fir/FirJsES6BoxTestGenerated.java | 6 ++++++ .../js/test/ir/IrBoxJsES6TestGenerated.java | 6 ++++++ .../js/test/ir/IrBoxJsTestGenerated.java | 6 ++++++ .../classInheritsJsNameFromOtherModule.kt | 20 +++++++++++++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 84e2e49053b..c10b21e310e 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -777,7 +777,7 @@ fun FirDeclaration.hasAnnotationOrInsideAnnotatedClass(classId: ClassId, session symbol.hasAnnotationOrInsideAnnotatedClass(classId, session) fun FirBasedSymbol<*>.getAnnotationFirstArgument(classId: ClassId, session: FirSession): FirExpression? { - val annotation = getAnnotationByClassId(classId, session) as? FirAnnotationCall + val annotation = getAnnotationByClassId(classId, session) return annotation?.argumentMapping?.mapping?.values?.firstOrNull() } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java index c7019850bd0..9b318abab28 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java @@ -5142,6 +5142,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest { runTest("js/js.translator/testData/box/inheritance/childPrototype.kt"); } + @Test + @TestMetadata("classInheritsJsNameFromOtherModule.kt") + public void testClassInheritsJsNameFromOtherModule() throws Exception { + runTest("js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt"); + } + @Test @TestMetadata("complexInitializationOrder.kt") public void testComplexInitializationOrder() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java index a65f4910b00..e120bddc7e6 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java @@ -5248,6 +5248,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest { runTest("js/js.translator/testData/box/inheritance/childPrototype.kt"); } + @Test + @TestMetadata("classInheritsJsNameFromOtherModule.kt") + public void testClassInheritsJsNameFromOtherModule() throws Exception { + runTest("js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt"); + } + @Test @TestMetadata("complexInitializationOrder.kt") public void testComplexInitializationOrder() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java index 7e6bc6ec458..07c323db025 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java @@ -5248,6 +5248,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/inheritance/childPrototype.kt"); } + @Test + @TestMetadata("classInheritsJsNameFromOtherModule.kt") + public void testClassInheritsJsNameFromOtherModule() throws Exception { + runTest("js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt"); + } + @Test @TestMetadata("complexInitializationOrder.kt") public void testComplexInitializationOrder() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index 1037d63fb90..7ab57f16c2c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -5142,6 +5142,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/inheritance/childPrototype.kt"); } + @Test + @TestMetadata("classInheritsJsNameFromOtherModule.kt") + public void testClassInheritsJsNameFromOtherModule() throws Exception { + runTest("js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt"); + } + @Test @TestMetadata("complexInitializationOrder.kt") public void testComplexInitializationOrder() throws Exception { diff --git a/js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt b/js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt new file mode 100644 index 00000000000..56d885bfa89 --- /dev/null +++ b/js/js.translator/testData/box/inheritance/classInheritsJsNameFromOtherModule.kt @@ -0,0 +1,20 @@ +// MODULE: lib +// FILE: TestDemo1.kt +package TestDemo1 + +abstract class Class { + open val ok = "OK" + + @JsName("okFun") + fun ok() = ok +} + +// FILE: TestDemo2.kt +// MODULE: main(lib) +package TestDemo2 + +import TestDemo1.Class + +class MyClass : Class() + +fun box() = MyClass().ok()