From 043f3199c7280e461af0352fc147244dfc1d31c6 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 29 Dec 2016 13:37:59 +0100 Subject: [PATCH] Fix for KT-15446: Property reference on an instance of subclass causes java.lang.VerifyError #KT-15446 Fixed --- .../kotlin/codegen/PropertyReferenceCodegen.kt | 5 ++--- .../box/callableReference/bound/array.kt | 11 +++++++++++ .../box/callableReference/bound/kt15446.kt | 15 +++++++++++++++ .../callableReference/bound/array.txt | 17 +++++++++++++++++ .../callableReference/bound/kt15446.txt | 4 ++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 12 ++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 12 ++++++++++++ .../LightAnalysisModeCodegenTestGenerated.java | 12 ++++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 18 ++++++++++++++++++ 9 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/callableReference/bound/array.kt create mode 100644 compiler/testData/codegen/box/callableReference/bound/kt15446.kt create mode 100644 compiler/testData/codegen/light-analysis/callableReference/bound/array.txt create mode 100644 compiler/testData/codegen/light-analysis/callableReference/bound/kt15446.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt index 25f5efaed8f..8c0f83eb734 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt @@ -256,9 +256,8 @@ class PropertyReferenceCodegen( } if (receiverType != null) { - val expectedReceiver = target.dispatchReceiverParameter ?: target.extensionReceiverParameter ?: - throw AssertionError("receiverType: $receiverType; no dispatch or extension receiver: $target") - val expectedReceiverType = typeMapper.mapType(expectedReceiver.type) + val expectedReceiver = target.extensionReceiverParameter?.type ?: (target.containingDeclaration as? ClassDescriptor)?.defaultType + val expectedReceiverType = if (expectedReceiver != null) typeMapper.mapType(expectedReceiver) else receiverType capturedBoundReferenceReceiver(asmType, expectedReceiverType, isInliningStrategy).put(expectedReceiverType, v) } else { diff --git a/compiler/testData/codegen/box/callableReference/bound/array.kt b/compiler/testData/codegen/box/callableReference/bound/array.kt new file mode 100644 index 00000000000..2a78bb9cc88 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/bound/array.kt @@ -0,0 +1,11 @@ +open class A { + var f: String = "OK" +} + +class B : A() { +} + +fun box() : String { + val b = B() + return (b::f).get() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/bound/kt15446.kt b/compiler/testData/codegen/box/callableReference/bound/kt15446.kt new file mode 100644 index 00000000000..967150ab7cb --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/bound/kt15446.kt @@ -0,0 +1,15 @@ +//WITH_RUNTIME +// IGNORE_BACKEND: JS +fun box(): String { + val a = intArrayOf(1, 2) + val b = arrayOf("OK") + if ((a::component2)() != 2) { + return "fail" + } + + if ((a::get)(1) != 2) { + return "fail" + } + + return (b::get)(0) +} \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/callableReference/bound/array.txt b/compiler/testData/codegen/light-analysis/callableReference/bound/array.txt new file mode 100644 index 00000000000..9ac92fe8e7c --- /dev/null +++ b/compiler/testData/codegen/light-analysis/callableReference/bound/array.txt @@ -0,0 +1,17 @@ +@kotlin.Metadata +public class A { + private @org.jetbrains.annotations.NotNull field f: java.lang.String + public method (): void + public final @org.jetbrains.annotations.NotNull method getF(): java.lang.String + public final method setF(@org.jetbrains.annotations.NotNull p0: java.lang.String): void +} + +@kotlin.Metadata +public final class ArrayKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} + +@kotlin.Metadata +public final class B { + public method (): void +} diff --git a/compiler/testData/codegen/light-analysis/callableReference/bound/kt15446.txt b/compiler/testData/codegen/light-analysis/callableReference/bound/kt15446.txt new file mode 100644 index 00000000000..37733ad434b --- /dev/null +++ b/compiler/testData/codegen/light-analysis/callableReference/bound/kt15446.txt @@ -0,0 +1,4 @@ +@kotlin.Metadata +public final class Kt15446Kt { + 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 6169d0484d5..5b7ccb1ca5f 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 @@ -1501,6 +1501,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/bound"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/array.kt"); + doTest(fileName); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1525,6 +1531,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt15446.kt") + public void testKt15446() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/kt15446.kt"); + doTest(fileName); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 2a42d860d18..ead2492392d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1501,6 +1501,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/bound"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/array.kt"); + doTest(fileName); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1525,6 +1531,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt15446.kt") + public void testKt15446() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/kt15446.kt"); + doTest(fileName); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index 738a3637bb0..8afba6527ed 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -1501,6 +1501,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/bound"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/array.kt"); + doTest(fileName); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1525,6 +1531,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis doTest(fileName); } + @TestMetadata("kt15446.kt") + public void testKt15446() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/kt15446.kt"); + doTest(fileName); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.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 275847c9fe0..c3bba46ec50 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 @@ -1868,6 +1868,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/callableReference/bound"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("array.kt") + public void testArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/array.kt"); + doTest(fileName); + } + @TestMetadata("companionObjectReceiver.kt") public void testCompanionObjectReceiver() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); @@ -1910,6 +1916,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("kt15446.kt") + public void testKt15446() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/kt15446.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt");