From c80901bafad85f697669bc2f4dfb092401ccf671 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 2 Jun 2014 13:11:45 +0400 Subject: [PATCH] KT-5112 Generic signature lost for a field copied from class object to containing class #KT-5112 Fixed --- .../codegen/ImplementationBodyCodegen.java | 3 ++- .../boxWithStdlib/reflection/kt5112.kt | 26 +++++++++++++++++++ ...lackBoxWithStdlibCodegenTestGenerated.java | 5 ++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index ea9ce3c0314..91aa59a8906 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -1030,7 +1030,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { PropertyDescriptor property = info.descriptor; FieldVisitor fv = v.newField(null, ACC_STATIC | ACC_FINAL | ACC_PUBLIC, context.getFieldName(property, false), - typeMapper.mapType(property).getDescriptor(), null, info.defaultValue); + typeMapper.mapType(property).getDescriptor(), typeMapper.mapFieldSignature(property.getType()), + info.defaultValue); AnnotationCodegen.forField(fv, typeMapper).genAnnotations(property); diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt b/compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt new file mode 100644 index 00000000000..8fc13b4a219 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt @@ -0,0 +1,26 @@ +package test + +class G(val s: T) { + +} + +public trait ErrorsJvmTrait { + class object { + public val param : G = G("STRING") + } +} + +public class ErrorsJvmClass { + class object { + public val param : G = G("STRING") + } +} + +fun box(): String { + val genericType = javaClass().getField("param").getGenericType() + if (genericType.toString() != "test.G") return "fail1: $genericType" + + val genericType2 = javaClass().getField("param").getGenericType() + if (genericType2.toString() != "test.G") return "fail1: genericType2" + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 65df1b36754..b4a5d55a063 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1222,6 +1222,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("kt5112.kt") + public void testKt5112() throws Exception { + doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/kt5112.kt"); + } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/insideLambda") public static class InsideLambda extends AbstractBlackBoxCodegenTest { public void testAllFilesPresentInInsideLambda() throws Exception {