From b989bfce5996c53923db578c7bb0ef5b8a052528 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 8 Feb 2017 14:17:58 +0300 Subject: [PATCH] Fix VerifyError with @JvmStatic annotated getter The problem was that for property getter 'context.getContextDescriptor()' references the containing property, while 'context.getFunctionDescriptor()' the accessor itself #KT-15594 Fixed --- .../jetbrains/kotlin/codegen/ExpressionCodegen.java | 2 +- .../jvmStatic/propertyGetterDelegatesToAnother.kt | 12 ++++++++++++ .../jvmStatic/propertyGetterDelegatesToAnother.txt | 12 ++++++++++++ .../codegen/ir/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/jvmStatic/propertyGetterDelegatesToAnother.kt create mode 100644 compiler/testData/codegen/light-analysis/jvmStatic/propertyGetterDelegatesToAnother.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 423977238ca..7ecf85d1a1f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3192,7 +3192,7 @@ public class ExpressionCodegen extends KtVisitor impleme boolean isSingleton = calleeContainingClass.getKind().isSingleton(); if (isSingleton) { if (calleeContainingClass.equals(context.getThisDescriptor()) && - !CodegenUtilKt.isJvmStaticInObjectOrClass(context.getContextDescriptor())) { + !CodegenUtilKt.isJvmStaticInObjectOrClass(context.getFunctionDescriptor())) { return StackValue.local(0, typeMapper.mapType(calleeContainingClass)); } else if (isEnumEntry(calleeContainingClass)) { diff --git a/compiler/testData/codegen/box/jvmStatic/propertyGetterDelegatesToAnother.kt b/compiler/testData/codegen/box/jvmStatic/propertyGetterDelegatesToAnother.kt new file mode 100644 index 00000000000..767a0b188ae --- /dev/null +++ b/compiler/testData/codegen/box/jvmStatic/propertyGetterDelegatesToAnother.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +// TARGET_BACKEND: JVM +object ObjectThisTest { + + val testValue: String + @JvmStatic get() = this.testValue2 + + val testValue2: String + get() = "OK" +} + +fun box() = ObjectThisTest.testValue diff --git a/compiler/testData/codegen/light-analysis/jvmStatic/propertyGetterDelegatesToAnother.txt b/compiler/testData/codegen/light-analysis/jvmStatic/propertyGetterDelegatesToAnother.txt new file mode 100644 index 00000000000..c6432096c20 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/jvmStatic/propertyGetterDelegatesToAnother.txt @@ -0,0 +1,12 @@ +@kotlin.Metadata +public final class ObjectThisTest { + public final static field INSTANCE: ObjectThisTest + private method (): void + public final static @kotlin.jvm.JvmStatic @org.jetbrains.annotations.NotNull method getTestValue(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getTestValue2(): java.lang.String +} + +@kotlin.Metadata +public final class PropertyGetterDelegatesToAnotherKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index cf1009b0bf3..032ba15e24b 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -9740,6 +9740,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("propertyGetterDelegatesToAnother.kt") + public void testPropertyGetterDelegatesToAnother() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyGetterDelegatesToAnother.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index a480b384442..773e4be1ff6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -9740,6 +9740,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("propertyGetterDelegatesToAnother.kt") + public void testPropertyGetterDelegatesToAnother() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyGetterDelegatesToAnother.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/simple.kt");