From 9e6b706a03b36fc34c111b0caac5c61cb38c7304 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 28 Jul 2017 10:12:29 +0300 Subject: [PATCH] Unwrap property imported from object on property access #KT-18982 Fixed Target versions 1.1.5 --- .../org/jetbrains/kotlin/codegen/ExpressionCodegen.java | 9 +++++---- compiler/testData/codegen/box/objects/kt18982.kt | 9 +++++++++ .../codegen/ir/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/LightAnalysisModeTestGenerated.java | 6 ++++++ .../js/test/semantics/JsCodegenBoxTestGenerated.java | 6 ++++++ 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/box/objects/kt18982.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 9f766cc5a22..e1d2d33b8cb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -65,10 +65,7 @@ import org.jetbrains.kotlin.load.kotlin.TypeSignatureMappingKt; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt; -import org.jetbrains.kotlin.resolve.BindingContext; -import org.jetbrains.kotlin.resolve.BindingContextUtils; -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; -import org.jetbrains.kotlin.resolve.DescriptorUtils; +import org.jetbrains.kotlin.resolve.*; import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt; import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt; import org.jetbrains.kotlin.resolve.calls.model.*; @@ -1893,6 +1890,10 @@ public class ExpressionCodegen extends KtVisitor impleme return intermediateValueForSyntheticExtensionProperty((SyntheticJavaPropertyDescriptor) propertyDescriptor, receiver); } + if (propertyDescriptor instanceof PropertyImportedFromObject) { + propertyDescriptor = ((PropertyImportedFromObject) propertyDescriptor).getCallableFromObject(); + } + DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration(); FieldAccessorKind fieldAccessorKind = FieldAccessorKind.NORMAL; diff --git a/compiler/testData/codegen/box/objects/kt18982.kt b/compiler/testData/codegen/box/objects/kt18982.kt new file mode 100644 index 00000000000..daf03fb9bf6 --- /dev/null +++ b/compiler/testData/codegen/box/objects/kt18982.kt @@ -0,0 +1,9 @@ +import Foo.bar0 as bar + +object Foo { + val bar0 = "OK" + + fun test() = bar0 +} + +fun box() = Foo.test() \ No newline at end of file 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 681d109c453..2679eb94d01 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 @@ -11603,6 +11603,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt18982.kt") + public void testKt18982() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt18982.kt"); + doTest(fileName); + } + @TestMetadata("kt2398.kt") public void testKt2398() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt2398.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index a0d93710791..bde04226f1e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11603,6 +11603,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt18982.kt") + public void testKt18982() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt18982.kt"); + doTest(fileName); + } + @TestMetadata("kt2398.kt") public void testKt2398() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt2398.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6463b3b9ab6..d6045a3b904 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11603,6 +11603,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("kt18982.kt") + public void testKt18982() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt18982.kt"); + doTest(fileName); + } + @TestMetadata("kt2398.kt") public void testKt2398() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt2398.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 ff2df8c9164..be90bb4de8b 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 @@ -12959,6 +12959,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("kt18982.kt") + public void testKt18982() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt18982.kt"); + doTest(fileName); + } + @TestMetadata("kt2398.kt") public void testKt2398() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/objects/kt2398.kt");