From 944fa7e2f85d39142fdffa164b559a1994e0517b Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Fri, 10 Dec 2021 14:46:46 +0800 Subject: [PATCH] JVM IR: recover accidentally lost backingField (KT-49998) --- .../FirBlackBoxCodegenTestGenerated.java | 6 ++++ .../codegen/FirBytecodeTextTestGenerated.java | 6 ++++ .../jvm/MemoizedInlineClassReplacements.kt | 1 + .../annotationDefaultValueOfUnsigned.kt | 29 +++++++++++++++++++ .../annotationDefaultValueOfUnsigned.kt | 11 +++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 ++++ .../codegen/IrBytecodeTextTestGenerated.java | 6 ++++ 7 files changed, 65 insertions(+) create mode 100644 compiler/testData/codegen/box/annotations/annotationDefaultValueOfUnsigned.kt create mode 100644 compiler/testData/codegen/bytecodeText/annotationDefaultValueOfUnsigned.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 69b002e429b..2d43e3427f3 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -53,6 +53,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/annotatedObjectLiteral.kt"); } + @Test + @TestMetadata("annotationDefaultValueOfUnsigned.kt") + public void testAnnotationDefaultValueOfUnsigned() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationDefaultValueOfUnsigned.kt"); + } + @Test @TestMetadata("annotationOnWhen.kt") public void testAnnotationOnWhen() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java index 0118a6cee1f..f65835d4a8e 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java @@ -49,6 +49,12 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/annotationDefaultValue.kt"); } + @Test + @TestMetadata("annotationDefaultValueOfUnsigned.kt") + public void testAnnotationDefaultValueOfUnsigned() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/annotationDefaultValueOfUnsigned.kt"); + } + @Test @TestMetadata("annotationJavaRetentionPolicyRuntime.kt") public void testAnnotationJavaRetentionPolicyRuntime() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt index 0ec3bba6f75..c795727af82 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/MemoizedInlineClassReplacements.kt @@ -290,6 +290,7 @@ class MemoizedInlineClassReplacements( parent = propertySymbol.owner.parent copyAttributes(propertySymbol.owner) annotations = propertySymbol.owner.annotations + backingField = propertySymbol.owner.backingField } } correspondingPropertySymbol = property.symbol diff --git a/compiler/testData/codegen/box/annotations/annotationDefaultValueOfUnsigned.kt b/compiler/testData/codegen/box/annotations/annotationDefaultValueOfUnsigned.kt new file mode 100644 index 00000000000..91b99656a8b --- /dev/null +++ b/compiler/testData/codegen/box/annotations/annotationDefaultValueOfUnsigned.kt @@ -0,0 +1,29 @@ +// TARGET_BACKEND: JVM_IR +// WITH_STDLIB +// WITH_REFLECT +// FULL_JDK + +annotation class Ann1(val value: UByte = 41u) +annotation class Ann2(val value: UShort = 42u) +annotation class Ann3(val value: UInt = 43u) +annotation class Ann4(val value: ULong = 44u) + +@Ann1 +@Ann2 +@Ann3 +@Ann4 +class A + +fun box(): String { + val default1 = A::class.java.getAnnotation(Ann1::class.java).value + val default2 = A::class.java.getAnnotation(Ann2::class.java).value + val default3 = A::class.java.getAnnotation(Ann3::class.java).value + val default4 = A::class.java.getAnnotation(Ann4::class.java).value + + return if (default1 == 41u.toUByte() && + default2 == 42u.toUShort() && + default3 == 43u && + default4 == 44u.toULong() + ) "OK" + else "FAIL" +} diff --git a/compiler/testData/codegen/bytecodeText/annotationDefaultValueOfUnsigned.kt b/compiler/testData/codegen/bytecodeText/annotationDefaultValueOfUnsigned.kt new file mode 100644 index 00000000000..7dafc474b26 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/annotationDefaultValueOfUnsigned.kt @@ -0,0 +1,11 @@ +// TARGET_BACKEND: JVM_IR + +annotation class Ann1(val value: UByte = 41u) +annotation class Ann2(val value: UShort = 42u) +annotation class Ann3(val value: UInt = 43u) +annotation class Ann4(val value: ULong = 44u) + +// 1 default=\(byte\)41 +// 1 default=\(short\)42 +// 1 default=43 +// 1 default=44L \ No newline at end of file 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 2c873a70bfe..e5c06e18b8b 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 @@ -53,6 +53,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/annotatedObjectLiteral.kt"); } + @Test + @TestMetadata("annotationDefaultValueOfUnsigned.kt") + public void testAnnotationDefaultValueOfUnsigned() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationDefaultValueOfUnsigned.kt"); + } + @Test @TestMetadata("annotationOnWhen.kt") public void testAnnotationOnWhen() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java index 22017befa6a..451525b0f52 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java @@ -49,6 +49,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/annotationDefaultValue.kt"); } + @Test + @TestMetadata("annotationDefaultValueOfUnsigned.kt") + public void testAnnotationDefaultValueOfUnsigned() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/annotationDefaultValueOfUnsigned.kt"); + } + @Test @TestMetadata("annotationJavaRetentionPolicyRuntime.kt") public void testAnnotationJavaRetentionPolicyRuntime() throws Exception {