From d4c7d4fc7ce01ebb9fae344a991ddaa2ff19d016 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Sun, 15 Nov 2020 13:15:15 +0300 Subject: [PATCH] FIR: Fix callable references resolution with stub receivers Use stubReceiver as a receiver for fake calls See issues KT-43358 KT-43359 KT-43378 --- .../resolve/references/referenceToExtension.kt | 6 +++--- .../resolve/references/referenceToExtension.txt | 4 ++-- .../callableReferences/companions.kt | 4 ++-- .../callableReferences/companions.txt | 10 +++++----- .../resolve/calls/tower/FirTowerResolveTask.kt | 17 ++++++++--------- .../box/callableReference/bound/kt12738.kt | 1 - .../function/extensionInClassDisallowed.fir.kt | 4 ++-- ...erenceToCompanionObjectMemberViaClassName.kt | 2 +- ...ObjectMemberViaClassNameCompatibility.fir.kt | 2 +- .../postponedArgumentsAnalysis/basic.fir.kt | 2 +- .../tests/regressions/kt31975.fir.kt | 2 +- .../p-1/pos/1.2.fir.kt | 2 +- 12 files changed, 27 insertions(+), 29 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.kt b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.kt index f5853d4520e..721dae462a6 100644 --- a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.kt +++ b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.kt @@ -36,12 +36,12 @@ class NoGenericTest { fun B.extensionFun(): A = A() fun test_1() { - val extensionValRef = B::extensionVal - val extensionFunRef = B::extensionFun + val extensionValRef = B::extensionVal + val extensionFunRef = B::extensionFun } fun test_2() { val memberValRef = B::memberVal val memberFunRef = B::memberFun } -} \ No newline at end of file +} diff --git a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.txt b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.txt index 197c7e18a76..7245b85dce5 100644 --- a/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.txt +++ b/compiler/fir/analysis-tests/testData/resolve/references/referenceToExtension.txt @@ -81,8 +81,8 @@ FILE: referenceToExtension.kt } public final fun test_1(): R|kotlin/Unit| { - lval extensionValRef: = Q|NoGenericTest.B|::# - lval extensionFunRef: = Q|NoGenericTest.B|::# + lval extensionValRef: R|kotlin/reflect/KProperty1| = Q|NoGenericTest.B|::R|/NoGenericTest.extensionVal| + lval extensionFunRef: R|kotlin/reflect/KFunction1| = Q|NoGenericTest.B|::R|/NoGenericTest.extensionFun| } public final fun test_2(): R|kotlin/Unit| { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.kt index 17ef4ed5510..84bd92c2583 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.kt @@ -34,9 +34,9 @@ fun main() { foo3(KotlinClass::baz) // Type mismatch - foo1(KotlinClass::bar) + foo1(KotlinClass::bar) foo2(KotlinClass::bar) - foo3(KotlinClass::bar) + foo3(KotlinClass::bar) foo1(KotlinClass2::bar) // Type mismatch diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.txt index 57992cb5075..7dd469aa84b 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/companions.txt @@ -50,13 +50,13 @@ FILE: main.kt public final fun foo3(x: R|(kotlin/String) -> kotlin/Int|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - R|/foo1|(Q|KotlinClass|::R|/KotlinClass.Companion.baz|) + R|/foo1|(Q|KotlinClass|::R|/KotlinClass.baz|) R|/foo2|(Q|KotlinClass|::R|/KotlinClass.baz|) #(Q|KotlinClass|::R|/KotlinClass.baz|) - #(Q|KotlinClass|::#) + R|/foo1|(Q|KotlinClass|::R|/JavaClass.bar|) R|/foo2|(Q|KotlinClass|::R|/JavaClass.bar|) - R|/foo3|(Q|KotlinClass|::R|/JavaClass.bar|) - R|/foo1|(Q|KotlinClass2|::R|/KotlinClass2.Companion.bar|) + #(Q|KotlinClass|::R|/JavaClass.bar|) + R|/foo1|(Q|KotlinClass2|::R|/KotlinClass2.bar|) #(Q|KotlinClass2|::#) - R|/foo3|(Q|KotlinClass2|::R|/KotlinClass2.Companion.bar|) + R|/foo3|(Q|KotlinClass2|::R|/KotlinClass2.bar|) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt index bd6406e3af3..fbdf9a198a8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt @@ -180,16 +180,15 @@ internal open class FirTowerResolveTask( if (resolvedQualifier.symbol != null) { val typeRef = resolvedQualifier.typeRef - // NB: yet built-in Unit is used for "no-value" type - if (info.callKind == CallKind.CallableReference) { - if (info.stubReceiver != null || typeRef !is FirImplicitBuiltinTypeRef) { - runResolverForExpressionReceiver(info, resolvedQualifier, parentGroup = TowerGroup.QualifierValue) - } - } else { - if (typeRef !is FirImplicitBuiltinTypeRef) { - runResolverForExpressionReceiver(info, resolvedQualifier, parentGroup = TowerGroup.QualifierValue) - } + if (info.callKind == CallKind.CallableReference && info.stubReceiver != null ) { + runResolverForExpressionReceiver(info, info.stubReceiver, parentGroup = TowerGroup.QualifierValue) } + + // NB: yet built-in Unit is used for "no-value" type + if (typeRef !is FirImplicitBuiltinTypeRef) { + runResolverForExpressionReceiver(info, resolvedQualifier, parentGroup = TowerGroup.QualifierValue) + } + } } diff --git a/compiler/testData/codegen/box/callableReference/bound/kt12738.kt b/compiler/testData/codegen/box/callableReference/bound/kt12738.kt index 63fa78257c7..4a489ea9a34 100644 --- a/compiler/testData/codegen/box/callableReference/bound/kt12738.kt +++ b/compiler/testData/codegen/box/callableReference/bound/kt12738.kt @@ -1,6 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM // WASM_MUTE_REASON: BINDING_RECEIVERS -// IGNORE_BACKEND_FIR: JVM_IR fun get(t: T): () -> String { return t::toString } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt index 4362e431590..33d81eee6f6 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/extensionInClassDisallowed.fir.kt @@ -4,10 +4,10 @@ class A { fun A.extA(x: String) = x fun main() { - Int::extInt + Int::extInt A::extA - eat(Int::extInt) + eat(Int::extInt) eat(A::extA) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt b/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt index 1bcd9630ecb..cff0c2c0b0e 100644 --- a/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt +++ b/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt @@ -27,7 +27,7 @@ fun testA(a: A) { fun testB(b: B) { val call1 = call(B::foo) - call1 + call1 val call2 = call(B()::foo) call2 diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt b/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt index 2fe0def1097..8ad8bae69a0 100644 --- a/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt @@ -22,7 +22,7 @@ fun B.foo(): Double = 0.0 fun call(a: Any) {} fun testA(a: A) { - call(A::foo) + call(A::foo) call(A.Companion::foo) } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt index a8516c5a43e..54a6cbc882e 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt @@ -186,7 +186,7 @@ fun main() { // Should be error as `A3::foo1` is `KFunction2`, but the remaining arguments are `KFuncion1` or `Function1` ")!>select(A3(), ")!>A3::foo1, { a -> a }, { it -> it }) // It's OK because `A3::foo2` is from companion of `A3` - ")!>select(A3(), ")!>A3::foo2, { a -> a }, { it -> it }) + ")!>select(A3(), ")!>A3::foo2, { a -> a }, { it -> it }) & java.io.Serializable>")!>select(A4(), { x: Number -> "" }) & java.io.Serializable>")!>select(A5(), { x: Number, y: Int -> "" }) ")!>select(A2(), id { a, b, c -> a; b; c }) diff --git a/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt index d26c5f6a750..a003b8815d1 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt31975.fir.kt @@ -11,7 +11,7 @@ interface TypeConstructor class Refiner { val memoizedFunctionLambda = createMemoizedFunction { it.foo() } // error type infered, no diagnostic, BAD, backend fails - val memoizedFunctionReference = createMemoizedFunction(TypeConstructor::foo) // EXTENSION_IN_CLASS_REFERENCE_IS_NOT_ALLOWED, fine + val memoizedFunctionReference = createMemoizedFunction(TypeConstructor::foo) // EXTENSION_IN_CLASS_REFERENCE_IS_NOT_ALLOWED, fine val memoizedFunctionTypes = createMemoizedFunction { it.foo() } // works fine private fun TypeConstructor.foo(): Boolean = true diff --git a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt index a8fd4601329..4b17a42c762 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/overload-resolution/resolving-callable-references/resolving-callable-references-not-used-as-arguments-to-a-call/p-1/pos/1.2.fir.kt @@ -11,7 +11,7 @@ import libCase1.* import kotlin.text.format fun case1() { - val y2 : () ->String =(String)::format + val y2 : () ->String =(String)::format } // FILE: LibCase1.kt