diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 2437e6fb5f9..06a598feb6f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -308,12 +308,7 @@ class FirCallResolver( val className = symbol.classId.shortClassName scope.processFunctionsByName(className) { if (it is FirConstructorSymbol) { - candidates += candidateFactory.createCandidate( - it, - dispatchReceiverValue = null, - implicitExtensionReceiverValue = null, - ExplicitReceiverKind.NO_EXPLICIT_RECEIVER - ) + candidates += candidateFactory.createCandidate(it, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER) } ProcessorAction.NEXT } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt index b967457aa72..971ae4c20ba 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt @@ -45,6 +45,13 @@ class CallInfo( val typeProvider: (FirExpression) -> FirTypeRef? ) { val argumentCount get() = arguments.size + + fun withReceiverAsArgument(receiverExpression: FirExpression): CallInfo = + CallInfo( + callKind, explicitReceiver, + listOf(receiverExpression) + arguments, + isSafeCall, typeArguments, session, containingFile, implicitReceiverStack, expectedType, outerCSBuilder, lhs, typeProvider + ) } enum class CandidateApplicability { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt index f04f3c7f0b8..b679d940f73 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateFactory.kt @@ -30,15 +30,18 @@ class CandidateFactory( fun createCandidate( symbol: AbstractFirBasedSymbol<*>, - dispatchReceiverValue: ClassDispatchReceiverValue?, - implicitExtensionReceiverValue: ImplicitReceiverValue<*>?, - explicitReceiverKind: ExplicitReceiverKind + explicitReceiverKind: ExplicitReceiverKind, + dispatchReceiverValue: ClassDispatchReceiverValue? = null, + implicitExtensionReceiverValue: ImplicitReceiverValue<*>? = null, + builtInExtensionFunctionReceiverValue: ReceiverValue? = null ): Candidate { - val candidate = Candidate( + return Candidate( symbol, dispatchReceiverValue, implicitExtensionReceiverValue, - explicitReceiverKind, bodyResolveComponents, baseSystem, callInfo + explicitReceiverKind, bodyResolveComponents, baseSystem, + builtInExtensionFunctionReceiverValue?.receiverExpression?.let { + callInfo.withReceiverAsArgument(it) + } ?: callInfo ) - return candidate } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index bbd9e3a19a2..e4aedf6d0cf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -8,9 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier -import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol @@ -139,23 +137,6 @@ internal object MapArguments : ResolutionStage() { override suspend fun check(candidate: Candidate, sink: CheckerSink, callInfo: CallInfo) { val symbol = candidate.symbol as? FirFunctionSymbol<*> ?: return sink.reportApplicability(CandidateApplicability.HIDDEN) val function = symbol.fir - if (candidate.dispatchReceiverValue?.type?.isBuiltinFunctionalType == true) { - // We don't know is it extension function or not due to lack of annotations - // So we have to check both variants, with receiver and without it - // TODO: remove this double-check after KT-30066 - val lambdaExtensionReceiver = - (callInfo.explicitReceiver as? FirQualifiedAccess)?.extensionReceiver?.takeIf { it !is FirNoReceiverExpression } - ?: (candidate.implicitExtensionReceiverValue as? ImplicitReceiverValue)?.receiverExpression - val processorWithReceiver = FirCallArgumentsProcessor( - function, - listOfNotNull(lambdaExtensionReceiver) + callInfo.arguments - ) - val mappingResult = processorWithReceiver.process() - candidate.argumentMapping = mappingResult.argumentMapping - if (mappingResult.isSuccess) { - return - } - } val processor = FirCallArgumentsProcessor(function, callInfo.arguments) val mappingResult = processor.process() candidate.argumentMapping = mappingResult.argumentMapping diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt index b3864ce0780..eb71927c460 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerDataConsumers.kt @@ -66,17 +66,13 @@ class QualifiedReceiverTowerDataConsumer>( override fun consumeCandidate( symbol: T, dispatchReceiverValue: ClassDispatchReceiverValue?, - implicitExtensionReceiverValue: ImplicitReceiverValue<*>? + implicitExtensionReceiverValue: ImplicitReceiverValue<*>?, + builtInExtensionFunctionReceiverValue: ReceiverValue? ): ProcessorAction { assert(dispatchReceiverValue == null) resultCollector.consumeCandidate( group, - candidateFactory.createCandidate( - symbol, - dispatchReceiverValue = null, - implicitExtensionReceiverValue = null, - explicitReceiverKind = ExplicitReceiverKind.NO_EXPLICIT_RECEIVER - ) + candidateFactory.createCandidate(symbol, explicitReceiverKind = ExplicitReceiverKind.NO_EXPLICIT_RECEIVER) ) return ProcessorAction.NEXT } @@ -203,15 +199,17 @@ class ExplicitReceiverTowerDataConsumer>( override fun consumeCandidate( symbol: T, dispatchReceiverValue: ClassDispatchReceiverValue?, - implicitExtensionReceiverValue: ImplicitReceiverValue<*>? + implicitExtensionReceiverValue: ImplicitReceiverValue<*>?, + builtInExtensionFunctionReceiverValue: ReceiverValue? ): ProcessorAction { resultCollector.consumeCandidate( group, candidateFactory.createCandidate( symbol, + ExplicitReceiverKind.DISPATCH_RECEIVER, dispatchReceiverValue, implicitExtensionReceiverValue, - ExplicitReceiverKind.DISPATCH_RECEIVER + builtInExtensionFunctionReceiverValue ) ) return ProcessorAction.NEXT @@ -222,7 +220,8 @@ class ExplicitReceiverTowerDataConsumer>( override fun consumeCandidate( symbol: T, dispatchReceiverValue: ClassDispatchReceiverValue?, - implicitExtensionReceiverValue: ImplicitReceiverValue<*>? + implicitExtensionReceiverValue: ImplicitReceiverValue<*>?, + builtInExtensionFunctionReceiverValue: ReceiverValue? ): ProcessorAction { if (symbol is FirNamedFunctionSymbol && symbol.callableId.packageName.startsWith(defaultPackage)) { val explicitReceiverType = explicitReceiver.type @@ -247,9 +246,10 @@ class ExplicitReceiverTowerDataConsumer>( } val candidate = candidateFactory.createCandidate( symbol, + ExplicitReceiverKind.EXTENSION_RECEIVER, dispatchReceiverValue, implicitExtensionReceiverValue, - ExplicitReceiverKind.EXTENSION_RECEIVER + builtInExtensionFunctionReceiverValue ) resultCollector.consumeCandidate( @@ -292,15 +292,17 @@ class NoExplicitReceiverTowerDataConsumer>( override fun consumeCandidate( symbol: T, dispatchReceiverValue: ClassDispatchReceiverValue?, - implicitExtensionReceiverValue: ImplicitReceiverValue<*>? + implicitExtensionReceiverValue: ImplicitReceiverValue<*>?, + builtInExtensionFunctionReceiverValue: ReceiverValue? ): ProcessorAction { resultCollector.consumeCandidate( group, candidateFactory.createCandidate( symbol, + ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, dispatchReceiverValue, implicitExtensionReceiverValue, - ExplicitReceiverKind.NO_EXPLICIT_RECEIVER + builtInExtensionFunctionReceiverValue ) ) return ProcessorAction.NEXT diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt index b1b241d74a4..11b627621dd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/TowerLevels.kt @@ -10,7 +10,9 @@ import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.impl.FirImportImpl import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedImportImpl +import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier +import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.firSymbolProvider @@ -46,7 +48,8 @@ interface TowerScopeLevel { fun consumeCandidate( symbol: T, dispatchReceiverValue: ClassDispatchReceiverValue?, - implicitExtensionReceiverValue: ImplicitReceiverValue<*>? + implicitExtensionReceiverValue: ImplicitReceiverValue<*>?, + builtInExtensionFunctionReceiverValue: ReceiverValue? ): ProcessorAction } @@ -100,6 +103,7 @@ class MemberScopeTowerLevel( private fun > processMembers( output: TowerScopeLevel.TowerScopeLevelProcessor, explicitExtensionReceiver: ExpressionReceiverValue?, + isInvoke: Boolean, processScopeMembers: FirScope.(processor: (T) -> ProcessorAction) -> ProcessorAction ): ProcessorAction { if (implicitExtensionReceiver != null && explicitExtensionReceiver != null) return ProcessorAction.NEXT @@ -109,9 +113,47 @@ class MemberScopeTowerLevel( if (candidate is FirCallableSymbol<*> && (invokeOnly || candidate.hasConsistentExtensionReceiver(extensionReceiver))) { // NB: we do not check dispatchReceiverValue != null here, // because of objects & constructors (see comments in dispatchReceiverValue() implementation) - output.consumeCandidate(candidate, candidate.dispatchReceiverValue(), implicitExtensionReceiver) + val dispatchReceiverValue = candidate.dispatchReceiverValue() + if (invokeOnly) { + if (output.consumeCandidate( + candidate, dispatchReceiverValue, + implicitExtensionReceiverValue = implicitExtensionReceiver, + builtInExtensionFunctionReceiverValue = null + ).stop() + ) { + ProcessorAction.STOP + } else { + output.consumeCandidate( + candidate, dispatchReceiverValue, + implicitExtensionReceiverValue = null, + builtInExtensionFunctionReceiverValue = implicitExtensionReceiver + ) + } + } else { + val builtInFunctionReceiverExpression = + if (!isInvoke || dispatchReceiver !is ExpressionReceiverValue) null + else (dispatchReceiver.explicitReceiverExpression as? FirQualifiedAccess)?.extensionReceiver + if (dispatchReceiver !is ExpressionReceiverValue || + builtInFunctionReceiverExpression == null || + builtInFunctionReceiverExpression is FirNoReceiverExpression + ) { + output.consumeCandidate(candidate, dispatchReceiverValue, implicitExtensionReceiver, null) + } else { + if (output.consumeCandidate(candidate, dispatchReceiverValue, implicitExtensionReceiver, null).stop()) { + ProcessorAction.STOP + } else { + output.consumeCandidate( + candidate, dispatchReceiverValue, + implicitExtensionReceiverValue = null, + builtInExtensionFunctionReceiverValue = ExpressionReceiverValue( + builtInFunctionReceiverExpression, dispatchReceiver.typeProvider + ) + ) + } + } + } } else if (candidate is FirClassLikeSymbol<*>) { - output.consumeCandidate(candidate, null, implicitExtensionReceiver) + output.consumeCandidate(candidate, null, implicitExtensionReceiver, null) } else { ProcessorAction.NEXT } @@ -119,7 +161,7 @@ class MemberScopeTowerLevel( ) return ProcessorAction.STOP val withSynthetic = FirSyntheticPropertiesScope(session, scope) return withSynthetic.processScopeMembers { symbol -> - output.consumeCandidate(symbol, symbol.dispatchReceiverValue(), implicitExtensionReceiver) + output.consumeCandidate(symbol, symbol.dispatchReceiverValue(), implicitExtensionReceiver, null) } } @@ -129,18 +171,19 @@ class MemberScopeTowerLevel( explicitReceiver: ExpressionReceiverValue?, processor: TowerScopeLevel.TowerScopeLevelProcessor ): ProcessorAction { - if (invokeOnly && (token != TowerScopeLevel.Token.Functions || name != OperatorNameConventions.INVOKE)) { + val isInvoke = name == OperatorNameConventions.INVOKE && token == TowerScopeLevel.Token.Functions + if (invokeOnly && !isInvoke) { return ProcessorAction.NEXT } val explicitExtensionReceiver = if (dispatchReceiver == explicitReceiver) null else explicitReceiver return when (token) { - TowerScopeLevel.Token.Properties -> processMembers(processor, explicitExtensionReceiver) { symbol -> + TowerScopeLevel.Token.Properties -> processMembers(processor, explicitExtensionReceiver, isInvoke) { symbol -> this.processPropertiesByName(name, symbol.cast()) } - TowerScopeLevel.Token.Functions -> processMembers(processor, explicitExtensionReceiver) { symbol -> + TowerScopeLevel.Token.Functions -> processMembers(processor, explicitExtensionReceiver, isInvoke) { symbol -> this.processFunctionsAndConstructorsByName(name, session, bodyResolveComponents, symbol.cast()) } - TowerScopeLevel.Token.Objects -> processMembers(processor, explicitExtensionReceiver) { symbol -> + TowerScopeLevel.Token.Objects -> processMembers(processor, explicitExtensionReceiver, isInvoke) { symbol -> this.processClassifiersByName(name, symbol.cast()) } } @@ -189,7 +232,8 @@ class ScopeTowerLevel( } processor.consumeCandidate( candidate as T, dispatchReceiverValue = dispatchReceiverValue, - implicitExtensionReceiverValue = implicitExtensionReceiver + implicitExtensionReceiverValue = implicitExtensionReceiver, + builtInExtensionFunctionReceiverValue = null ) } else { ProcessorAction.NEXT @@ -203,7 +247,8 @@ class ScopeTowerLevel( if (candidate.hasConsistentReceivers(extensionReceiver)) { processor.consumeCandidate( candidate as T, dispatchReceiverValue = candidate.dispatchReceiverValue(), - implicitExtensionReceiverValue = implicitExtensionReceiver + implicitExtensionReceiverValue = implicitExtensionReceiver, + builtInExtensionFunctionReceiverValue = null ) } else { ProcessorAction.NEXT @@ -212,7 +257,8 @@ class ScopeTowerLevel( TowerScopeLevel.Token.Objects -> scope.processClassifiersByName(name) { processor.consumeCandidate( it as T, dispatchReceiverValue = null, - implicitExtensionReceiverValue = null + implicitExtensionReceiverValue = null, + builtInExtensionFunctionReceiverValue = null ) } } @@ -259,7 +305,7 @@ class QualifiedReceiverTowerLevel( fir is FirConstructor && !fir.isInner ) { @Suppress("UNCHECKED_CAST") - processor.consumeCandidate(it as T, null, null) + processor.consumeCandidate(it as T, null, null, null) } else { ProcessorAction.NEXT } @@ -268,7 +314,7 @@ class QualifiedReceiverTowerLevel( return when (token) { TowerScopeLevel.Token.Objects -> scope.processClassifiersByName(name) { @Suppress("UNCHECKED_CAST") - processor.consumeCandidate(it as T, null, null) + processor.consumeCandidate(it as T, null, null, null) } TowerScopeLevel.Token.Functions -> { scope.processFunctionsAndConstructorsByName(name, session, bodyResolveComponents, processorForCallables) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt index bac7e9739ce..1c5e6808c2e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt @@ -134,8 +134,6 @@ class FirSyntheticCallGenerator( private fun generateCandidate(callInfo: CallInfo, function: FirSimpleFunctionImpl): Candidate = CandidateFactory(components, callInfo).createCandidate( symbol = function.symbol, - dispatchReceiverValue = null, - implicitExtensionReceiverValue = null, explicitReceiverKind = ExplicitReceiverKind.NO_EXPLICIT_RECEIVER ) diff --git a/compiler/fir/resolve/testData/resolve/expresssions/invoke/inBrackets.txt b/compiler/fir/resolve/testData/resolve/expresssions/invoke/inBrackets.txt index f19678b06ce..6a1cd22f4f3 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/invoke/inBrackets.txt +++ b/compiler/fir/resolve/testData/resolve/expresssions/invoke/inBrackets.txt @@ -1,5 +1,5 @@ FILE: inBrackets.kt public final fun test(e: R|kotlin/Int.() -> kotlin/String|): R|kotlin/Unit| { - lval s: R|kotlin/String| = Int(3).R|/e|.R|FakeOverride|() - lval ss: R|kotlin/String| = Int(3).R|/e|.R|FakeOverride|() + lval s: R|kotlin/String| = Int(3).R|/e|.R|FakeOverride|(Int(3)) + lval ss: R|kotlin/String| = Int(3).R|/e|.R|FakeOverride|(Int(3)) } diff --git a/compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyWithExtensionType.txt b/compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyWithExtensionType.txt index 9f9f1906fee..8a80f9ae8c5 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyWithExtensionType.txt +++ b/compiler/fir/resolve/testData/resolve/expresssions/invoke/propertyWithExtensionType.txt @@ -15,10 +15,10 @@ FILE: propertyWithExtensionType.kt when () { !=(R|/a|.R|/A.x|, Null(null)) -> { lval b: R|kotlin/String.() -> kotlin/Unit| = R|/a|.R|/A.x| - String().R|/b|.R|FakeOverride|() + String().R|/b|.R|FakeOverride|(String()) } } lval c: R|kotlin/String.() -> kotlin/Int| = R|/a|.R|/A.y| - lval d: R|kotlin/Int| = String().R|/c|.R|FakeOverride|() + lval d: R|kotlin/Int| = String().R|/c|.R|FakeOverride|(String()) } diff --git a/compiler/fir/resolve/testData/resolve/expresssions/invoke/threeReceivers.kt b/compiler/fir/resolve/testData/resolve/expresssions/invoke/threeReceivers.kt index 9ab37a82079..34db4610ae4 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/invoke/threeReceivers.kt +++ b/compiler/fir/resolve/testData/resolve/expresssions/invoke/threeReceivers.kt @@ -12,6 +12,10 @@ class Foo { val Buz.foobar: Bar get() = Bar() fun FooBar.chk(buz: Buz) { + // local/buz is extension receiver of foobar + // this@Foo is dispatch receiver of foobar + // Foo/foobar is dispatch receiver of invoke + // this@chk is extension receiver of invoke buz.foobar() } } diff --git a/compiler/fir/resolve/testData/resolve/expresssions/lambdaWithReceiver.txt b/compiler/fir/resolve/testData/resolve/expresssions/lambdaWithReceiver.txt index 4dd147d1194..375e49e6a13 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/lambdaWithReceiver.txt +++ b/compiler/fir/resolve/testData/resolve/expresssions/lambdaWithReceiver.txt @@ -4,10 +4,10 @@ FILE: lambdaWithReceiver.kt } public final fun myWith(receiver: R|T|, block: R|T.() -> kotlin/Unit|): R|kotlin/Unit| { - R|/receiver|.R|/block|.R|FakeOverride|() + R|/receiver|.R|/block|.R|FakeOverride|(R|/receiver|) } public final fun R|T|.myApply(block: R|T.() -> kotlin/Unit|): R|kotlin/Unit| { - this@R|/myApply|.R|/block|.R|FakeOverride|() + this@R|/myApply|.R|/block|.R|FakeOverride|(this@R|/myApply|) } public final fun withA(block: R|A.() -> kotlin/Unit|): R|kotlin/Unit| { } diff --git a/compiler/fir/resolve/testData/resolve/functionTypes.txt b/compiler/fir/resolve/testData/resolve/functionTypes.txt index 127a19df087..5975a07a19a 100644 --- a/compiler/fir/resolve/testData/resolve/functionTypes.txt +++ b/compiler/fir/resolve/testData/resolve/functionTypes.txt @@ -5,7 +5,7 @@ FILE: functionTypes.kt public final fun R|kotlin/collections/List|.simpleMap(f: R|(T) -> R|): R|R| { } public final fun simpleWith(t: R|T|, f: R|T.() -> kotlin/Unit|): R|kotlin/Unit| { - ^simpleWith R|/t|.R|/f|.R|FakeOverride|() + ^simpleWith R|/t|.R|/f|.R|FakeOverride|(R|/t|) } public abstract interface KMutableProperty1 : R|KProperty1|, R|KMutableProperty| { } diff --git a/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.kt b/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.kt index 5a76b07fb06..0d96614457c 100644 --- a/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.kt +++ b/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.kt @@ -4,12 +4,14 @@ fun test(a: A, block: A.() -> Int) { a.block() } -fun A.otherTest(block: A.() -> Int) { +interface B + +fun B.otherTest(block: B.() -> Int) { block() } -class B { - fun anotherTest(block: B.() -> Int) { +class C { + fun anotherTest(block: C.() -> Int) { block() } } \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.txt b/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.txt index fff1d35a17b..fabedb09b12 100644 --- a/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.txt +++ b/compiler/fir/resolve/testData/resolve/problems/invokeOfLambdaWithReceiver.txt @@ -2,18 +2,20 @@ FILE: invokeOfLambdaWithReceiver.kt public abstract interface A : R|kotlin/Any| { } public final fun test(a: R|A|, block: R|A.() -> kotlin/Int|): R|kotlin/Unit| { - R|/a|.R|/block|.R|FakeOverride|() + R|/a|.R|/block|.R|FakeOverride|(R|/a|) } - public final fun R|A|.otherTest(block: R|A.() -> kotlin/Int|): R|kotlin/Unit| { - (R|/block|, this@R|/otherTest|).R|FakeOverride|() + public abstract interface B : R|kotlin/Any| { } - public final class B : R|kotlin/Any| { - public constructor(): R|B| { + public final fun R|B|.otherTest(block: R|B.() -> kotlin/Int|): R|kotlin/Unit| { + R|/block|.R|FakeOverride|(this@R|/otherTest|) + } + public final class C : R|kotlin/Any| { + public constructor(): R|C| { super() } - public final fun anotherTest(block: R|B.() -> kotlin/Int|): R|kotlin/Unit| { - (R|/block|, this@R|/B|).R|FakeOverride|() + public final fun anotherTest(block: R|C.() -> kotlin/Int|): R|kotlin/Unit| { + R|/block|.R|FakeOverride|(this@R|/C|) } } diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt index 732cc6a9d27..6a739ab65e3 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.fir.kt @@ -26,7 +26,7 @@ fun fooT2() : (t : T) -> T { fun main(args : Array) { args.foo()() args.foo1()() - a.foo1()() + a.foo1()() a.foo1()(a) args.foo1()(1) diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt index f92766208d6..9345d87e3bc 100644 --- a/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/threeImplicitReceivers2.fir.kt @@ -35,37 +35,37 @@ fun test() { foo { bar { baz { - y() + y() x() with(D()) { - x() + x() } foo1 { - x() - y() + x() + y() with(A()) { - x() - y() + x() + y() } with(D()) { - x() + x() } A().x() } foo2 { - x() - y() + x() + y() } foo3 { - x() - y() + x() + y() } } } @@ -75,8 +75,8 @@ fun test() { foo { baz { bar { - x() - y() + x() + y() } } } @@ -86,8 +86,8 @@ fun test() { foo { baz { bar { - x() - y() + x() + y() } } } @@ -97,8 +97,8 @@ fun test() { foo { baz { bar { - x() - y() + x() + y() } } } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt index 77b688a36bf..f1cd1f5114c 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeOnVariableWithExtensionFunctionType.fir.kt @@ -24,10 +24,10 @@ fun test(a: A, b: B) { } with(b) { - a.foo() - a.(foo)() + a.foo() + a.(foo)() - (a.foo)() + (a.foo)() (a.foo)(this) a.foo(this) @@ -35,8 +35,8 @@ fun test(a: A, b: B) { with(a) { with(b) { - foo() - (foo)() + foo() + (foo)() } } } diff --git a/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.txt b/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.txt index aa47ff958f1..e1a41aae4f9 100644 --- a/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.txt +++ b/compiler/testData/ir/irText/expressions/extFunInvokeAsFun.fir.txt @@ -14,3 +14,4 @@ FILE fqName: fileName:/extFunInvokeAsFun.kt RETURN type=kotlin.Nothing from='public final fun with2 (receiver: kotlin.Any?, block: kotlin.Function1): kotlin.Unit declared in ' CALL 'public abstract fun invoke (p1: kotlin.Any?): kotlin.Unit [operator] declared in kotlin.Function1' type=kotlin.Unit origin=null $this: GET_VAR 'block: kotlin.Function1 declared in .with2' type=kotlin.Function1 origin=null + p1: GET_VAR 'receiver: kotlin.Any? declared in .with2' type=kotlin.Any? origin=null diff --git a/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.txt b/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.txt index 947b3899491..545275b15a3 100644 --- a/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.txt +++ b/compiler/testData/ir/irText/expressions/extFunSafeInvoke.fir.txt @@ -6,5 +6,6 @@ FILE fqName: fileName:/extFunSafeInvoke.kt RETURN type=kotlin.Nothing from='public final fun test (receiver: kotlin.Any?, fn: kotlin.Function3): kotlin.Unit? declared in ' CALL 'public abstract fun invoke (p1: kotlin.Any, p2: kotlin.Int, p3: kotlin.String): kotlin.Unit [operator] declared in kotlin.Function3' type=kotlin.Unit? origin=null $this: GET_VAR 'fn: kotlin.Function3 declared in .test' type=kotlin.Function3 origin=null - p1: CONST Int type=kotlin.Int value=42 - p2: CONST String type=kotlin.String value="Hello" + p1: GET_VAR 'receiver: kotlin.Any? declared in .test' type=kotlin.Any? origin=null + p2: CONST Int type=kotlin.Int value=42 + p3: CONST String type=kotlin.String value="Hello" diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt index f0cbf79fc4a..c922dac4e17 100644 --- a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.fir.txt @@ -19,6 +19,7 @@ FILE fqName: fileName:/variableAsFunctionCall.kt RETURN type=kotlin.Nothing from='public final fun test2 (f: kotlin.Function1): kotlin.Unit declared in ' CALL 'public abstract fun invoke (p1: kotlin.String): kotlin.Unit [operator] declared in kotlin.Function1' type=kotlin.Unit origin=null $this: GET_VAR 'f: kotlin.Function1 declared in .test2' type=kotlin.Function1 origin=null + p1: CONST String type=kotlin.String value="hello" FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.String declared in '