From 5ab05e6e479282805d58bdf0e2e4caf8a49d1562 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 10 Jun 2020 16:24:09 +0300 Subject: [PATCH] FIR: Fix incorrect resolution to synthetic property by implicit receiver When there's an explicit one ^KT-39028 Fixed --- ...yntheticPropertiesWrongImplicitReceiver.kt | 21 ++++++++++++ ...ntheticPropertiesWrongImplicitReceiver.txt | 33 +++++++++++++++++++ .../fir/FirDiagnosticsTestGenerated.java | 5 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 5 +++ .../fir/resolve/calls/tower/TowerLevels.kt | 6 ++-- 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.kt b/compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.kt new file mode 100644 index 00000000000..2cecc8cec85 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.kt @@ -0,0 +1,21 @@ +// !CHECK_TYPE +// FILE: JavaClass.java +public class JavaClass { + public String getFoo() { + return ""; + } +} + +// FILE: main.kt + +interface A + +val A.foo: Int get() = 1 + +fun bar(a: A) { + a.foo checkType { _() } // OK, resolved to extension property +} + +fun JavaClass.bar(a: A) { + a.foo checkType { _() } +} diff --git a/compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.txt b/compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.txt new file mode 100644 index 00000000000..9e7d91a50ef --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.txt @@ -0,0 +1,33 @@ +FILE: main.kt + public abstract interface A : R|kotlin/Any| { + } + public final val R|A|.foo: R|kotlin/Int| + public get(): R|kotlin/Int| { + ^ Int(1) + } + public final fun bar(a: R|A|): R|kotlin/Unit| { + R|/a|.R|/foo|.R|tests/_checkType/checkType|(checkType@fun R|tests/_checkType/Inv|.(): R|kotlin/Unit| { + this@R|special/anonymous|.R|tests/_checkType/_|() + } + ) + } + public final fun R|JavaClass|.bar(a: R|A|): R|kotlin/Unit| { + R|/a|.R|/foo|.R|tests/_checkType/checkType|(checkType@fun R|tests/_checkType/Inv|.(): R|kotlin/Unit| { + this@R|special/anonymous|.R|tests/_checkType/_|() + } + ) + } +FILE: CHECK_TYPE.kt + public final fun checkSubtype(t: R|T|): R|T| { + ^checkSubtype R|/t| + } + public final class Inv : R|kotlin/Any| { + public constructor(): R|tests/_checkType/Inv| { + super() + } + + } + public final fun R|tests/_checkType/Inv|._(): R|kotlin/Unit| { + } + public final infix fun R|T|.checkType(f: R|tests/_checkType/Inv.() -> kotlin/Unit|): R|kotlin/Unit| { + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 35d6a0b8503..61082eb2a7d 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -634,6 +634,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/safeCallOnTypeAlias.kt"); } + @TestMetadata("syntheticPropertiesWrongImplicitReceiver.kt") + public void testSyntheticPropertiesWrongImplicitReceiver() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.kt"); + } + @TestMetadata("typeAliasWithNotNullBound.kt") public void testTypeAliasWithNotNullBound() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 090ad7a94ed..255dda8aefa 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -634,6 +634,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/safeCallOnTypeAlias.kt"); } + @TestMetadata("syntheticPropertiesWrongImplicitReceiver.kt") + public void testSyntheticPropertiesWrongImplicitReceiver() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/syntheticPropertiesWrongImplicitReceiver.kt"); + } + @TestMetadata("typeAliasWithNotNullBound.kt") public void testTypeAliasWithNotNullBound() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/callResolution/typeAliasWithNotNullBound.kt"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt index 1180f125f9b..9b950fffe3a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt @@ -26,9 +26,9 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirExplicitSimpleImportingScope import org.jetbrains.kotlin.fir.scopes.processClassifiersByName import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* -import org.jetbrains.kotlin.fir.types.classId import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeNullability +import org.jetbrains.kotlin.fir.types.classId import org.jetbrains.kotlin.fir.types.withNullability import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.util.OperatorNameConventions @@ -117,11 +117,11 @@ class MemberScopeTowerLevel( } } - if (!forInnerConstructorDelegationCalls) { + if (!forInnerConstructorDelegationCalls && extensionReceiver == null) { val withSynthetic = FirSyntheticPropertiesScope(session, scope) withSynthetic.processScopeMembers { symbol -> empty = false - output.consumeCandidate(symbol, NotNullableReceiverValue(dispatchReceiver), extensionReceiver as? ImplicitReceiverValue<*>) + output.consumeCandidate(symbol, NotNullableReceiverValue(dispatchReceiver), null) } } return if (empty) ProcessorAction.NONE else ProcessorAction.NEXT