diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index 0d53964e9b4..387a1fd9a9d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -374,6 +374,11 @@ public abstract class MemberCodegen initializerValue = computeInitializerValue(property, propertyDescriptor, initializer); diff --git a/compiler/testData/codegen/box/constants/kt9532.kt b/compiler/testData/codegen/box/constants/kt9532.kt new file mode 100644 index 00000000000..a2fef198d23 --- /dev/null +++ b/compiler/testData/codegen/box/constants/kt9532.kt @@ -0,0 +1,30 @@ +object A { + const val a: String = "$" + const val b = "1234$a" + const val c = 10000 + + val bNonConst = "1234$a" + val bNullable: String = "1234$a" +} + +object B { + const val a: String = "$" + const val b = "1234$a" + const val c = 10000 + + val bNonConst = "1234$a" + val bNullable: String = "1234$a" +} + +fun box(): String { + if (A.a !== B.a) return "Fail 1: A.a !== B.a" + + if (A.b !== B.b) return "Fail 2: A.b !== B.b" + + if (A.c !== B.c) return "Fail 3: A.c !== B.c" + + if (A.bNonConst === B.bNonConst) return "Fail 5: A.bNonConst == B.bNonConst" + if (A.bNullable === B.bNullable) return "Fail 6: A.bNullable == B.bNullable" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/JavaClass.java b/compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/JavaClass.java new file mode 100644 index 00000000000..df79bb0b350 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/JavaClass.java @@ -0,0 +1,16 @@ +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class JavaClass { + + @Retention(RetentionPolicy.RUNTIME) + @interface Foo { + int value(); + } + + @Foo(KotlinInterface.FOO_INT) + public String test() throws NoSuchMethodException { + return KotlinInterface.FOO_STRING + + JavaClass.class.getMethod("test").getAnnotation(Foo.class).value(); + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/KotlinInterface.kt b/compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/KotlinInterface.kt new file mode 100644 index 00000000000..0aca6fad078 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/KotlinInterface.kt @@ -0,0 +1,11 @@ +interface KotlinInterface { + companion object { + const val FOO_INT: Int = 10 + const val FOO_STRING: String = "OK" + } +} + +fun box(): String { + val test = JavaClass().test() + return if (test == "OK10") "OK" else "fail : $test" +} diff --git a/compiler/testData/codegen/boxWithStdlib/const/interfaceCompanion.kt b/compiler/testData/codegen/boxWithStdlib/const/interfaceCompanion.kt new file mode 100644 index 00000000000..9b602a5a5e9 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/const/interfaceCompanion.kt @@ -0,0 +1,18 @@ +interface KInt { + + companion object { + const val a = "a" + const val b = "b$a" + } +} + +fun box(): String { + val a = KInt::class.java.getField("a").get(null) + val b = KInt::class.java.getField("b").get(null) + + if (a !== KInt.a) return "fail 1: KInt.a !== KInt.Companion.a" + if (b !== KInt.b) return "fail 2: KInt.b !== KInt.Companion.b" + if (b !== "ba") return "fail 2: 'ba' !== KInt.Companion.b" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/constants/kt9532.kt b/compiler/testData/codegen/bytecodeText/constants/kt9532.kt new file mode 100644 index 00000000000..cad1a1dfc79 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/constants/kt9532.kt @@ -0,0 +1,10 @@ +object A { + private const val a = "$" + private const val b = "1234$a" + private const val c = 10000 +} + +//check that constant initializers inlined + +// 0 GETSTATIC +// 2 PUTSTATIC A.INSTANCE diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 0d3c4c3cf26..60bae7c3447 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -469,6 +469,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("kt9532.kt") + public void testKt9532() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/kt9532.kt"); + doTest(fileName); + } + @TestMetadata("nullableByteAndShort.kt") public void testNullableByteAndShort() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index f9865a8b930..ca0fb7791db 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -1960,6 +1960,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt9532.kt") + public void testKt9532() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/constants/kt9532.kt"); + doTest(fileName); + } + @TestMetadata("long.kt") public void testLong() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/constants/long.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 09cbd9dee28..9328b171265 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -387,6 +387,12 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege doTestWithJava(fileName); } + @TestMetadata("annotationWithKotlinPropertyFromInterfaceCompanion") + public void testAnnotationWithKotlinPropertyFromInterfaceCompanion() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/properties/annotationWithKotlinPropertyFromInterfaceCompanion/"); + doTestWithJava(fileName); + } + @TestMetadata("classObjectProperties") public void testClassObjectProperties() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/properties/classObjectProperties/"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index a083cd94868..48d6b4bd508 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1070,6 +1070,21 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode } } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/const") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Const extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInConst() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/const"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("interfaceCompanion.kt") + public void testInterfaceCompanion() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/const/interfaceCompanion.kt"); + doTestWithStdlib(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxWithStdlib/controlStructures") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)