From f836d16dc6c52fde04f4bd7bf4f52b9b2860a828 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 20 Feb 2023 12:56:36 +0200 Subject: [PATCH] [FIR] Don't generate synthetic declarations from java records from binary dependencies ^KT-56548 Fixed --- ...BlackBoxModernJdkCodegenTestGenerated.java | 6 ++++++ .../kotlin/fir/java/FirJavaFacade.kt | 5 ++++- .../testsWithJava17/records/binaryRecord.kt | 21 +++++++++++++++++++ ...BlackBoxModernJdkCodegenTestGenerated.java | 6 ++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxModernJdk/testsWithJava17/records/binaryRecord.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxModernJdkCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxModernJdkCodegenTestGenerated.java index 3e78446458a..a1479df5111 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxModernJdkCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxModernJdkCodegenTestGenerated.java @@ -340,6 +340,12 @@ public class FirLightTreeBlackBoxModernJdkCodegenTestGenerated extends AbstractF KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxModernJdk/testsWithJava17/records"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("binaryRecord.kt") + public void testBinaryRecord() throws Exception { + runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/binaryRecord.kt"); + } + @Test @TestMetadata("bytecodeShapeForJava.kt") public void testBytecodeShapeForJava() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt index b6e35e8c0fa..e04c8875a6a 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/FirJavaFacade.kt @@ -364,7 +364,10 @@ abstract class FirJavaFacade( moduleData = moduleData, ) } - if (javaClass.isRecord) { + + // There is no need to generated synthetic declarations for java record from binary dependencies + // because they are actually present in .class files + if (javaClass.isRecord && javaClass.isFromSource) { createDeclarationsForJavaRecord( javaClass, classId, diff --git a/compiler/testData/codegen/boxModernJdk/testsWithJava17/records/binaryRecord.kt b/compiler/testData/codegen/boxModernJdk/testsWithJava17/records/binaryRecord.kt new file mode 100644 index 00000000000..63217159e8f --- /dev/null +++ b/compiler/testData/codegen/boxModernJdk/testsWithJava17/records/binaryRecord.kt @@ -0,0 +1,21 @@ +// TARGET_BACKEND: JVM_IR +// ISSUE: KT-56548 + +// MODULE: m1 +// FILE: SomeWrapper.java +public final class SomeWrapper { + public record SomeRecord(String a, String b) {} +} + +// MODULE: m2(m1) +// FILE: test.kt +import SomeWrapper.SomeRecord + +fun testBinary(s: String): String { + val record = SomeRecord(s, "K") + return record.a + record.b +} + +fun box(): String { + return testBinary("O") +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxModernJdkCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxModernJdkCodegenTestGenerated.java index 6848bd2e9f9..777192d914a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxModernJdkCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxModernJdkCodegenTestGenerated.java @@ -340,6 +340,12 @@ public class IrBlackBoxModernJdkCodegenTestGenerated extends AbstractIrBlackBoxC KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxModernJdk/testsWithJava17/records"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("binaryRecord.kt") + public void testBinaryRecord() throws Exception { + runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/binaryRecord.kt"); + } + @Test @TestMetadata("bytecodeShapeForJava.kt") public void testBytecodeShapeForJava() throws Exception {