From 4c9bac084c3c9587d6965e1889ef61f4e80888df Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Tue, 27 Dec 2016 10:52:20 +0100 Subject: [PATCH] Fix for KT-15437: VerifyError: Bad local variable type on simplest provideDelegate #KT-15437 Fixed --- .../kotlin/codegen/MemberCodegen.java | 5 ----- .../provideDelegate/hostCheck.kt | 14 +++++++++++++ .../provideDelegate/kt15437.kt | 12 +++++++++++ .../provideDelegate/hostCheck.txt | 20 +++++++++++++++++++ .../provideDelegate/kt15437.txt | 12 +++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 12 +++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 12 +++++++++++ ...LightAnalysisModeCodegenTestGenerated.java | 12 +++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 12 +++++++++++ 9 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt create mode 100644 compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/hostCheck.txt create mode 100644 compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/kt15437.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index 78580cb60cd..8d5b94ee0cf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -493,11 +493,6 @@ public abstract class MemberCodegen arguments = provideDelegateResolvedCall.getCall().getValueArguments(); - assert arguments.size() == 2 : - "Resolved call for '" + OperatorNameConventions.PROVIDE_DELEGATE.asString() + "' should have exactly 2 value parameters"; - codegen.tempVariables.put(arguments.get(0).asElement(), StackValue.LOCAL_0); - StackValue delegateValue = PropertyCodegen.invokeDelegatedPropertyConventionMethodWithReceiver( codegen, typeMapper, provideDelegateResolvedCall, indexOfDelegatedProperty, 1, provideDelegateReceiver); diff --git a/compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt b/compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt new file mode 100644 index 00000000000..788f19e57d0 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt @@ -0,0 +1,14 @@ +import kotlin.reflect.KProperty + +class Delegate(val value: String) { + operator fun provideDelegate(instance: A, property: KProperty<*>): Delegate = Delegate(instance.value) + operator fun getValue(instance: Any?, property: KProperty<*>) = value +} + +class A(val value: String) { + val result: String by Delegate("Fail") +} + +fun box(): String { + return A("OK").result +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt b/compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt new file mode 100644 index 00000000000..85d54e3cc18 --- /dev/null +++ b/compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt @@ -0,0 +1,12 @@ +import kotlin.reflect.KProperty + +class Delegate { + operator fun provideDelegate(instance: Any?, property: KProperty<*>): Delegate = this + operator fun getValue(instance: Any?, property: KProperty<*>) = "OK" +} + +val result: String by Delegate() + +fun box(): String { + return result +} \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/hostCheck.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/hostCheck.txt new file mode 100644 index 00000000000..b212c9f8e4c --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/hostCheck.txt @@ -0,0 +1,20 @@ +public final class A { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + private final @org.jetbrains.annotations.NotNull field result$delegate: Delegate + private final @org.jetbrains.annotations.NotNull field value: java.lang.String + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final @org.jetbrains.annotations.NotNull method getResult(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getValue(): java.lang.String +} + +public final class Delegate { + private final @org.jetbrains.annotations.NotNull field value: java.lang.String + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String): void + public final @org.jetbrains.annotations.NotNull method getValue(): java.lang.String + public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): java.lang.String + public final @org.jetbrains.annotations.NotNull method provideDelegate(@org.jetbrains.annotations.NotNull p0: A, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): Delegate +} + +public final class HostCheckKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/kt15437.txt b/compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/kt15437.txt new file mode 100644 index 00000000000..9b5d9ee920c --- /dev/null +++ b/compiler/testData/codegen/light-analysis/delegatedProperty/provideDelegate/kt15437.txt @@ -0,0 +1,12 @@ +public final class Delegate { + public method (): void + public final @org.jetbrains.annotations.NotNull method getValue(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): java.lang.String + public final @org.jetbrains.annotations.NotNull method provideDelegate(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.reflect.KProperty): Delegate +} + +public final class Kt15437Kt { + private synthetic final static field $$delegatedProperties: kotlin.reflect.KProperty[] + private final static @org.jetbrains.annotations.NotNull field result$delegate: Delegate + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static @org.jetbrains.annotations.NotNull method getResult(): 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 fc60b1cafbf..529e9548710 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 @@ -6115,6 +6115,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("hostCheck.kt") + public void testHostCheck() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt"); + doTest(fileName); + } + @TestMetadata("inClass.kt") public void testInClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/inClass.kt"); @@ -6133,6 +6139,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt15437.kt") + public void testKt15437() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/local.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 6ac4f80e843..9bea324e0e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6115,6 +6115,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("hostCheck.kt") + public void testHostCheck() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt"); + doTest(fileName); + } + @TestMetadata("inClass.kt") public void testInClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/inClass.kt"); @@ -6133,6 +6139,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt15437.kt") + public void testKt15437() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/local.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index ca2388a1656..5f4e459859e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -6115,6 +6115,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis doTest(fileName); } + @TestMetadata("hostCheck.kt") + public void testHostCheck() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt"); + doTest(fileName); + } + @TestMetadata("inClass.kt") public void testInClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/inClass.kt"); @@ -6133,6 +6139,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis doTest(fileName); } + @TestMetadata("kt15437.kt") + public void testKt15437() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/local.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index fdec455de65..00033fdfa0c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -7016,6 +7016,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("hostCheck.kt") + public void testHostCheck() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/hostCheck.kt"); + doTest(fileName); + } + @TestMetadata("inClass.kt") public void testInClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/inClass.kt"); @@ -7040,6 +7046,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("kt15437.kt") + public void testKt15437() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/kt15437.kt"); + doTest(fileName); + } + @TestMetadata("local.kt") public void testLocal() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegatedProperty/provideDelegate/local.kt");