diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt index 82e86505165..83d83e549b6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/FunctionDescriptorResolver.kt @@ -198,9 +198,11 @@ class FunctionDescriptorResolver( } val contextReceivers = function.contextReceivers - val contextReceiverTypes = contextReceivers.mapNotNull { it.typeReference() }.map { - typeResolver.resolveType(headerScope, it, trace, true) - } + val contextReceiverTypes = + if (function is KtFunctionLiteral) expectedFunctionType.getContextReceiversTypes() + else contextReceivers + .mapNotNull { it.typeReference() } + .map { typeResolver.resolveType(headerScope, it, trace, true) } val valueParameterDescriptors = createValueParameterDescriptors(function, functionDescriptor, headerScope, trace, expectedFunctionType, inferenceSession) @@ -351,6 +353,9 @@ class FunctionDescriptorResolver( private fun KotlinType.getReceiverType(): KotlinType? = if (functionTypeExpected()) this.getReceiverTypeFromFunctionType() else null + private fun KotlinType.getContextReceiversTypes(): List = + if (functionTypeExpected()) this.getContextReceiverTypesFromFunctionType() else emptyList() + private fun KotlinType.getValueParameters(owner: FunctionDescriptor): List? = if (functionTypeExpected()) { createValueParametersForInvokeInFunctionType(owner, this.getValueParameterTypesFromFunctionType()) diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.fir.kt index 294a81c6d04..983d5793dc0 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.fir.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.fir.kt @@ -1,6 +1,10 @@ class Param -class C -class R +class C { + val c = 42 +} +class R { + val r = 42 +} context(C) fun R.f1(g: context(C) R.(Param) -> Unit) { @@ -23,10 +27,20 @@ fun f4(g: context(C) () -> Unit) { } fun test() { - val lf1: context(C) R.(Param) -> Unit = { _ -> } - val lf2: context(C) (Param) -> Unit = { _ -> } - val lf3: context(C) R.() -> Unit = { } - val lf4: context(C) () -> Unit = { } + val lf1: context(C) R.(Param) -> Unit = { _ -> + r + c + } + val lf2: context(C) (Param) -> Unit = { _ -> + c + } + val lf3: context(C) R.() -> Unit = { + r + c + } + val lf4: context(C) () -> Unit = { + c + } with(C()) { with(R()) { diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.kt index 294a81c6d04..983d5793dc0 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.kt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.kt @@ -1,6 +1,10 @@ class Param -class C -class R +class C { + val c = 42 +} +class R { + val r = 42 +} context(C) fun R.f1(g: context(C) R.(Param) -> Unit) { @@ -23,10 +27,20 @@ fun f4(g: context(C) () -> Unit) { } fun test() { - val lf1: context(C) R.(Param) -> Unit = { _ -> } - val lf2: context(C) (Param) -> Unit = { _ -> } - val lf3: context(C) R.() -> Unit = { } - val lf4: context(C) () -> Unit = { } + val lf1: context(C) R.(Param) -> Unit = { _ -> + r + c + } + val lf2: context(C) (Param) -> Unit = { _ -> + c + } + val lf3: context(C) R.() -> Unit = { + r + c + } + val lf4: context(C) () -> Unit = { + c + } with(C()) { with(R()) { diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.txt index 3e9f1008d50..1c94626caf6 100644 --- a/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.txt +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/functionalType.txt @@ -8,6 +8,7 @@ public fun R.f3(/*0*/ g: @kotlin.ContextFunctionTypeParams(count = 1) (R.() -> k public final class C { public constructor C() + public final val c: kotlin.Int = 42 public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String @@ -22,6 +23,7 @@ public final class Param { public final class R { public constructor R() + public final val r: kotlin.Int = 42 public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String