From a5771c6c1c7da89e63dc9ef04b3dc3d9ceae6b9e Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Tue, 10 Nov 2015 14:14:30 +0300 Subject: [PATCH] Fix for KT-9939: java.lang.VerifyError: Bad type on operand stack for Boolean convenience accessor #KT-9939 Fixed --- .../jetbrains/kotlin/codegen/StackValue.java | 3 ++- .../javaProperty/boxedGetter/JavaClass.java | 12 ++++++++++ .../javaProperty/boxedGetter/kotlin.kt | 13 +++++++++++ .../javaProperty/boxedSetter/JavaClass.java | 12 ++++++++++ .../javaProperty/boxedSetter/kotlin.kt | 11 ++++++++++ .../BlackBoxWithJavaCodegenTestGenerated.java | 22 +++++++++++++++++++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/JavaClass.java create mode 100644 compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/kotlin.kt create mode 100644 compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/JavaClass.java create mode 100644 compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/kotlin.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java index 03ff9b57ef6..c11ddcbb9b4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/StackValue.java @@ -1127,13 +1127,14 @@ public abstract class StackValue { @Override public void storeSelector(@NotNull Type topOfStackType, @NotNull InstructionAdapter v) { - coerceFrom(topOfStackType, v); if (setter == null) { + coerceFrom(topOfStackType, v); assert fieldName != null : "Property should have either a setter or a field name: " + descriptor; assert backingFieldOwner != null : "Property should have either a setter or a backingFieldOwner: " + descriptor; v.visitFieldInsn(isStaticStore ? PUTSTATIC : PUTFIELD, backingFieldOwner.getInternalName(), fieldName, this.type.getDescriptor()); } else { + coerce(topOfStackType, ArraysKt.last(setter.getParameterTypes()), v); setter.genInvokeInstruction(v); } } diff --git a/compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/JavaClass.java b/compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/JavaClass.java new file mode 100644 index 00000000000..f499564b631 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/JavaClass.java @@ -0,0 +1,12 @@ +public class JavaClass { + + private Boolean value; + + public Boolean isValue() { + return value; + } + + public void setValue(boolean value) { + this.value = value; + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/kotlin.kt b/compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/kotlin.kt new file mode 100644 index 00000000000..eb6c8219fc2 --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/kotlin.kt @@ -0,0 +1,13 @@ +fun box(): String { + val javaClass = JavaClass() + + if (javaClass.isValue != null) return "fail 1" + + javaClass.isValue = false + if (javaClass.isValue != false) return "fail 2" + + javaClass.isValue = true + if (javaClass.isValue != true) return "fail 3" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/JavaClass.java b/compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/JavaClass.java new file mode 100644 index 00000000000..ef4c6ae312c --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/JavaClass.java @@ -0,0 +1,12 @@ +public class JavaClass { + + private boolean value; + + public boolean isValue() { + return value; + } + + public void setValue(Boolean value) { + this.value = value; + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/kotlin.kt b/compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/kotlin.kt new file mode 100644 index 00000000000..808731f722b --- /dev/null +++ b/compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/kotlin.kt @@ -0,0 +1,11 @@ +fun box(): String { + val javaClass = JavaClass() + + if (javaClass.isValue != false) return "fail 1" + + javaClass.isValue = true + + if (javaClass.isValue != true) return "fail 2" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java index 6b642d8bf85..7a573832f0e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithJavaCodegenTestGenerated.java @@ -351,6 +351,28 @@ public class BlackBoxWithJavaCodegenTestGenerated extends AbstractBlackBoxCodege } + @TestMetadata("compiler/testData/codegen/boxWithJava/javaProperty") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JavaProperty extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInJavaProperty() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithJava/javaProperty"), Pattern.compile("^([^\\.]+)$"), true); + } + + @TestMetadata("boxedGetter") + public void testBoxedGetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/javaProperty/boxedGetter/"); + doTestWithJava(fileName); + } + + @TestMetadata("boxedSetter") + public void testBoxedSetter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxWithJava/javaProperty/boxedSetter/"); + doTestWithJava(fileName); + } + + } + @TestMetadata("compiler/testData/codegen/boxWithJava/jvmField") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)