From 397cc4f7720a41a5f1359a42050c405f94a15035 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 20 Apr 2018 08:12:31 +0300 Subject: [PATCH] [NI] Support implicit invoke calls on parenthesized receivers --- .../resolve/calls/tower/PSICallResolver.kt | 74 ++++++++++++------- .../resolve/calls/tower/PSIKotlinCalls.kt | 1 + .../resolve/calls/KotlinCallResolver.kt | 17 ++++- .../calls/components/ResolutionParts.kt | 6 +- .../resolve/calls/model/ArgumentsImpl.kt | 2 - .../kotlin/resolve/calls/model/KotlinCall.kt | 41 +++++----- .../calls/model/KotlinResolverContext.kt | 1 + ...anonymousObjectAsLastExpressionInLambda.kt | 36 +++++++++ .../tests/FunctionCalleeExpressions.kt | 4 +- .../throwOutCandidatesByReceiver.kt | 2 +- .../inner/innerConstructorsFromQualifiers.kt | 2 +- .../errors/typeInferenceErrorForInvoke.kt | 2 +- .../wrongReceiverForInvokeOnExpression.kt | 12 +-- .../resolve/invoke/invokeAndSmartCast.kt | 4 +- .../thisAndSuper/implicitInvokeOnSuper.kt | 15 ++++ .../thisAndSuper/implicitInvokeOnSuper.txt | 20 +++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++ .../checkers/DiagnosticsTestGenerated.java | 6 ++ .../DiagnosticsUsingJavacTestGenerated.java | 6 ++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++ .../LightAnalysisModeTestGenerated.java | 6 ++ .../semantics/JsCodegenBoxTestGenerated.java | 6 ++ 22 files changed, 211 insertions(+), 64 deletions(-) create mode 100644 compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index c2d339a3270..5c53e0c09e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.referenceExpression import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver +import org.jetbrains.kotlin.resolve.calls.CallTransformer import org.jetbrains.kotlin.resolve.calls.KotlinCallResolver import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isBinaryRemOperator import org.jetbrains.kotlin.resolve.calls.callUtil.createLookupLocation @@ -66,7 +67,8 @@ class PSICallResolver( val defaultResolutionKinds = setOf( NewResolutionOldInference.ResolutionKind.Function, - NewResolutionOldInference.ResolutionKind.Variable + NewResolutionOldInference.ResolutionKind.Variable, + NewResolutionOldInference.ResolutionKind.Invoke ) fun runResolutionAndInference( @@ -78,23 +80,23 @@ class PSICallResolver( val isBinaryRemOperator = isBinaryRemOperator(context.call) val refinedName = refineNameForRemOperator(isBinaryRemOperator, name) - val kotlinCall = toKotlinCall(context, resolutionKind.toKotlinCallKind(), context.call, refinedName, tracingStrategy) + val kotlinCallKind = resolutionKind.toKotlinCallKind() + val kotlinCall = toKotlinCall(context, kotlinCallKind, context.call, refinedName, tracingStrategy) val scopeTower = ASTScopeTower(context) val resolutionCallbacks = createResolutionCallbacks(context) - val factoryProviderForInvoke = FactoryProviderForInvoke(context, scopeTower, kotlinCall) - val expectedType = calculateExpectedType(context) - var result = kotlinCallResolver.resolveCall( - scopeTower, resolutionCallbacks, kotlinCall, expectedType, factoryProviderForInvoke, context.collectAllCandidates - ) + var result = + kotlinCallResolver.resolveCall(scopeTower, resolutionCallbacks, kotlinCall, expectedType, context.collectAllCandidates) { + FactoryProviderForInvoke(context, scopeTower, kotlinCall) + } val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem) if (isBinaryRemOperator && shouldUseOperatorRem && (result.isEmpty() || result.areAllInapplicable())) { - result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, scopeTower, resolutionCallbacks, expectedType) + result = resolveToDeprecatedMod(name, context, kotlinCallKind, tracingStrategy, scopeTower, resolutionCallbacks, expectedType) } - if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind, kotlinCall)) { + if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, kotlinCallKind, kotlinCall)) { return OverloadResolutionResultsImpl.nameNotFound() } @@ -126,25 +128,24 @@ class PSICallResolver( scopeTower, resolutionCallbacks, kotlinCall, calculateExpectedType(context), givenCandidates, context.collectAllCandidates ) return convertToOverloadResolutionResults(context, result, tracingStrategy) - } private fun resolveToDeprecatedMod( remOperatorName: Name, context: BasicCallResolutionContext, - resolutionKind: NewResolutionOldInference.ResolutionKind, + kotlinCallKind: KotlinCallKind, tracingStrategy: TracingStrategy, scopeTower: ImplicitScopeTower, resolutionCallbacks: KotlinResolutionCallbacksImpl, expectedType: UnwrappedType? ): CallResolutionResult { val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[remOperatorName]!! - val callWithDeprecatedName = toKotlinCall(context, resolutionKind.toKotlinCallKind(), context.call, deprecatedName, tracingStrategy) - val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, scopeTower, callWithDeprecatedName) + val callWithDeprecatedName = toKotlinCall(context, kotlinCallKind, context.call, deprecatedName, tracingStrategy) return kotlinCallResolver.resolveCall( - scopeTower, resolutionCallbacks, callWithDeprecatedName, expectedType, - refinedProviderForInvokeFactory, context.collectAllCandidates - ) + scopeTower, resolutionCallbacks, callWithDeprecatedName, expectedType, context.collectAllCandidates + ) { + FactoryProviderForInvoke(context, scopeTower, callWithDeprecatedName) + } } private fun refineNameForRemOperator(isBinaryRemOperator: Boolean, name: Name): Name { @@ -303,7 +304,7 @@ class PSICallResolver( private fun reportAdditionalDiagnosticIfNoCandidates( context: BasicCallResolutionContext, scopeTower: ImplicitScopeTower, - kind: NewResolutionOldInference.ResolutionKind, + kind: KotlinCallKind, kotlinCall: KotlinCall ): Boolean { val reference = context.call.calleeExpression as? KtReferenceExpression ?: return false @@ -451,15 +452,14 @@ class PSICallResolver( } } - private fun NewResolutionOldInference.ResolutionKind.toKotlinCallKind(): KotlinCallKind { - return when (this) { + private fun NewResolutionOldInference.ResolutionKind.toKotlinCallKind(): KotlinCallKind = + when (this) { is NewResolutionOldInference.ResolutionKind.Function -> KotlinCallKind.FUNCTION is NewResolutionOldInference.ResolutionKind.Variable -> KotlinCallKind.VARIABLE - is NewResolutionOldInference.ResolutionKind.Invoke -> KotlinCallKind.UNSUPPORTED + is NewResolutionOldInference.ResolutionKind.Invoke -> KotlinCallKind.INVOKE is NewResolutionOldInference.ResolutionKind.CallableReference -> KotlinCallKind.UNSUPPORTED is NewResolutionOldInference.ResolutionKind.GivenCandidates -> KotlinCallKind.UNSUPPORTED } - } private fun toKotlinCall( context: BasicCallResolutionContext, @@ -469,8 +469,11 @@ class PSICallResolver( tracingStrategy: TracingStrategy, forcedExplicitReceiver: Receiver? = null ): PSIKotlinCallImpl { - val resolvedExplicitReceiver = - resolveExplicitReceiver(context, forcedExplicitReceiver ?: oldCall.explicitReceiver, oldCall.isSafeCall()) + val resolvedExplicitReceiver = resolveReceiver( + context, forcedExplicitReceiver ?: oldCall.explicitReceiver, oldCall.isSafeCall(), isVariableReceiverForInvoke = false + ) + val dispatchReceiverForInvoke = resolveDispatchReceiverForInvoke(context, kotlinCallKind, oldCall) + val resolvedTypeArguments = resolveTypeArguments(context, oldCall.typeArguments) val argumentsInParenthesis = if (oldCall.callType != Call.CallType.ARRAY_SET_METHOD && oldCall.functionLiteralArguments.isEmpty()) { @@ -510,15 +513,30 @@ class PSICallResolver( astExternalArgument?.setResultDataFlowInfoIfRelevant(resultDataFlowInfo) return PSIKotlinCallImpl( - kotlinCallKind, oldCall, tracingStrategy, resolvedExplicitReceiver, name, resolvedTypeArguments, - resolvedArgumentsInParenthesis, astExternalArgument, context.dataFlowInfo, resultDataFlowInfo, context.dataFlowInfoForArguments + kotlinCallKind, oldCall, tracingStrategy, resolvedExplicitReceiver, dispatchReceiverForInvoke, name, + resolvedTypeArguments, resolvedArgumentsInParenthesis, astExternalArgument, context.dataFlowInfo, resultDataFlowInfo, + context.dataFlowInfoForArguments ) } - private fun resolveExplicitReceiver( + private fun resolveDispatchReceiverForInvoke( + context: BasicCallResolutionContext, + kotlinCallKind: KotlinCallKind, + oldCall: Call + ): ReceiverKotlinCallArgument? { + if (kotlinCallKind != KotlinCallKind.INVOKE) return null + + require(oldCall is CallTransformer.CallForImplicitInvoke) { "Call should be CallForImplicitInvoke, but it is: $oldCall" } + + val dispatchReceiver = oldCall.dispatchReceiver!! // dispatch receiver from CallForImplicitInvoke is always not null + return resolveReceiver(context, dispatchReceiver, isSafeCall = false, isVariableReceiverForInvoke = true) + } + + private fun resolveReceiver( context: BasicCallResolutionContext, oldReceiver: Receiver?, - isSafeCall: Boolean + isSafeCall: Boolean, + isVariableReceiverForInvoke: Boolean ): ReceiverKotlinCallArgument? = when (oldReceiver) { null -> null @@ -546,7 +564,7 @@ class PSICallResolver( } } - subCallArgument ?: ReceiverExpressionKotlinCallArgument(detailedReceiver, isSafeCall) + subCallArgument ?: ReceiverExpressionKotlinCallArgument(detailedReceiver, isSafeCall, isVariableReceiverForInvoke) } else -> error("Incorrect receiver: $oldReceiver") } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt index 621b0d5404d..7ce0851d645 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSIKotlinCalls.kt @@ -50,6 +50,7 @@ class PSIKotlinCallImpl( override val psiCall: Call, override val tracingStrategy: TracingStrategy, override val explicitReceiver: ReceiverKotlinCallArgument?, + override val dispatchReceiverForInvokeExtension: ReceiverKotlinCallArgument?, override val name: Name, override val typeArguments: List, override val argumentsInParenthesis: List, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt index 1ac0c9fa5c3..9a5b028433b 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.components.NewOverloadingConflictResol import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.* +import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.UnwrappedType import java.lang.UnsupportedOperationException @@ -39,8 +40,8 @@ class KotlinCallResolver( resolutionCallbacks: KotlinResolutionCallbacks, kotlinCall: KotlinCall, expectedType: UnwrappedType?, - factoryProviderForInvoke: CandidateFactoryProviderForInvoke, - collectAllCandidates: Boolean + collectAllCandidates: Boolean, + createFactoryProviderForInvoke: () -> CandidateFactoryProviderForInvoke ): CallResolutionResult { kotlinCall.checkCallInvariants() @@ -54,10 +55,20 @@ class KotlinCallResolver( scopeTower, kotlinCall.name, candidateFactory, - factoryProviderForInvoke, + createFactoryProviderForInvoke(), kotlinCall.explicitReceiver?.receiver ) } + KotlinCallKind.INVOKE -> { + createProcessorWithReceiverValueOrEmpty(kotlinCall.explicitReceiver?.receiver) { + createCallTowerProcessorForExplicitInvoke( + scopeTower, + candidateFactory, + kotlinCall.dispatchReceiverForInvokeExtension?.receiver as ReceiverValueWithSmartCastInfo, + it + ) + } + } KotlinCallKind.UNSUPPORTED -> throw UnsupportedOperationException() } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 11ad03d61bc..d04296ebe73 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -205,7 +205,11 @@ internal object CheckExplicitReceiverKindConsistency : ResolutionPart() { override fun KotlinResolutionCandidate.process(workIndex: Int) { when (resolvedCall.explicitReceiverKind) { NO_EXPLICIT_RECEIVER -> if (kotlinCall.explicitReceiver is SimpleKotlinCallArgument || kotlinCall.dispatchReceiverForInvokeExtension != null) hasError() - DISPATCH_RECEIVER, EXTENSION_RECEIVER -> if (kotlinCall.explicitReceiver == null || kotlinCall.dispatchReceiverForInvokeExtension != null) hasError() + DISPATCH_RECEIVER, EXTENSION_RECEIVER -> + if (kotlinCall.callKind == KotlinCallKind.INVOKE && kotlinCall.dispatchReceiverForInvokeExtension == null || + kotlinCall.callKind != KotlinCallKind.INVOKE && + (kotlinCall.explicitReceiver == null || kotlinCall.dispatchReceiverForInvokeExtension != null) + ) hasError() BOTH_RECEIVERS -> if (kotlinCall.explicitReceiver == null || kotlinCall.dispatchReceiverForInvokeExtension == null) hasError() } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentsImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentsImpl.kt index 856439d0a68..597cd4a8888 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentsImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ArgumentsImpl.kt @@ -16,10 +16,8 @@ package org.jetbrains.kotlin.resolve.calls.model -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo -import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.prepareReceiverRegardingCaptureTypes diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt index ce3bd5bcde0..5d0e440a320 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCall.kt @@ -43,27 +43,32 @@ fun KotlinCall.checkCallInvariants() { explicitReceiver.safeAs()?.checkReceiverInvariants() dispatchReceiverForInvokeExtension.safeAs()?.checkReceiverInvariants() - if (callKind != KotlinCallKind.FUNCTION) { - assert(externalArgument == null) { - "External argument is not allowed not for function call: $externalArgument." - } - assert(argumentsInParenthesis.isEmpty()) { - "Arguments in parenthesis should be empty for not function call: $this " - } - assert(dispatchReceiverForInvokeExtension == null) { - "Dispatch receiver for invoke should be null for not function call: $dispatchReceiverForInvokeExtension" - } - } else { - assert(externalArgument == null || !externalArgument!!.isSpread) { - "External argument cannot nave spread element: $externalArgument" + when (callKind) { + KotlinCallKind.FUNCTION, KotlinCallKind.INVOKE -> { + assert(externalArgument == null || !externalArgument!!.isSpread) { + "External argument cannot nave spread element: $externalArgument" + } + assert(externalArgument?.argumentName == null) { + "Illegal external argument with name: $externalArgument" + } + assert(dispatchReceiverForInvokeExtension == null || !dispatchReceiverForInvokeExtension!!.isSafeCall) { + "Dispatch receiver for invoke cannot be safe: $dispatchReceiverForInvokeExtension" + } } - assert(externalArgument?.argumentName == null) { - "Illegal external argument with name: $externalArgument" + KotlinCallKind.VARIABLE -> { + assert(externalArgument == null) { + "External argument is not allowed not for function call: $externalArgument." + } + assert(argumentsInParenthesis.isEmpty()) { + "Arguments in parenthesis should be empty for not function call: $this " + } + assert(dispatchReceiverForInvokeExtension == null) { + "Dispatch receiver for invoke should be null for not function call: $dispatchReceiverForInvokeExtension" + } + } - assert(dispatchReceiverForInvokeExtension == null || !dispatchReceiverForInvokeExtension!!.isSafeCall) { - "Dispatch receiver for invoke cannot be safe: $dispatchReceiverForInvokeExtension" - } + KotlinCallKind.UNSUPPORTED -> error("Call with UNSUPPORTED kind") } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt index 1c3dc1ed4f6..07eb8099c83 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt @@ -207,6 +207,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { CheckArguments, CheckExternalArgument ), + INVOKE(*FUNCTION.resolutionSequence.toTypedArray()), UNSUPPORTED(); val resolutionSequence = resolutionPart.asList() diff --git a/compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt b/compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt new file mode 100644 index 00000000000..e66015ff4fa --- /dev/null +++ b/compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +NewInference +// WITH_RUNTIME + +object A { + var result = "not ok" +} + +fun test1() { + run { + (A) { + A.result = "OK" + } + } +} + +object B + +operator fun A.invoke(x: () -> Unit) { + x() +} + +operator fun Pair.invoke(f: (x: K, y: V) -> Boolean): Boolean = f(this.first, this.second) +inline fun Any.isType(): Boolean = this is T + +fun test2(): Boolean { + return (A to B) { k, v -> k.isType() && v.isType() } +} + +fun box(): String { + test1() + if (A.result != "OK") return "fail1: ${A.result}" + + if (!test2()) return "fail2" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt index b6b63869a51..34a0db2f3fb 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt @@ -37,8 +37,8 @@ fun main(args : Array) { foo2()({}) foo2(){} (foo2()){} - (foo2()){x -> } - foo2()({x -> }) + (foo2()){x -> } + foo2()({x -> }) val a = fooT1(1)() checkSubtype(a) diff --git a/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.kt b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.kt index 41853015366..f6aae337302 100644 --- a/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.kt +++ b/compiler/testData/diagnostics/tests/extensions/throwOutCandidatesByReceiver.kt @@ -35,7 +35,7 @@ fun test4() { // should be an error on receiver, shouldn't be thrown away fun test5() { - 1.(fun String.()=1)() + 1.(fun String.()=1)() } fun R?.sure() : R = this!! diff --git a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt index 5a2c9ff2cbd..e831c7955a3 100644 --- a/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt +++ b/compiler/testData/diagnostics/tests/inner/innerConstructorsFromQualifiers.kt @@ -33,4 +33,4 @@ fun bar() { Inner() Inner(1) } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt index e80e3bc5fb6..4e079470edd 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/typeInferenceErrorForInvoke.kt @@ -10,5 +10,5 @@ fun foo(s: String, ai: A) { s(ai) - ""(ai) + ""(ai) } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.kt b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.kt index 7a85f50e76d..af96d5c2b83 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/errors/wrongReceiverForInvokeOnExpression.kt @@ -1,15 +1,17 @@ +// !WITH_NEW_INFERENCE + fun test1() { - 1. (fun String.(i: Int) = i )(1) - 1.(label@ fun String.(i: Int) = i )(1) + 1. (fun String.(i: Int) = i )(1) + 1.(label@ fun String.(i: Int) = i )(1) } fun test2(f: String.(Int) -> Unit) { - 11.(f)(1) - 11.(f)() + 11.(f)(1) + 11.(f)() } fun test3() { fun foo(): String.(Int) -> Unit = {} - 1.(foo())(1) + 1.(foo())(1) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt index fee7c010b3b..0f119bc2f3e 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt @@ -9,11 +9,11 @@ fun test(a: A) { } "".(a.x)() a.x("") - (a.x)("") + (a.x)("") with("") { a.x() - (a.x)() + (a.x)() if (a.x != null) { a.x() // todo (a.x)() diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.kt b/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.kt new file mode 100644 index 00000000000..a997400e73f --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.kt @@ -0,0 +1,15 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class A { + operator fun invoke() {} + operator fun invoke(f: () -> Unit) {} +} + +class B : A() { + fun bar() { + super() + (super)() + super {} + (super) {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.txt b/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.txt new file mode 100644 index 00000000000..61b63eefcc9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.txt @@ -0,0 +1,20 @@ +package + +public open class A { + public constructor A() + 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 final operator fun invoke(): kotlin.Unit + public final operator fun invoke(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class B : A { + public constructor B() + public final fun bar(): kotlin.Unit + 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 final override /*1*/ /*fake_override*/ fun invoke(): kotlin.Unit + public final override /*1*/ /*fake_override*/ fun invoke(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 bb59e3cf5ad..e71aa32900c 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 @@ -3274,6 +3274,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("anonymousObjectAsLastExpressionInLambda.kt") + public void testAnonymousObjectAsLastExpressionInLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt"); + doTest(fileName); + } + @TestMetadata("captureExtensionReceiver.kt") public void testCaptureExtensionReceiver() throws Exception { runTest("compiler/testData/codegen/box/closures/captureExtensionReceiver.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 9d9f8c7edea..f8f4ad1f58e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -20989,6 +20989,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.kt"); } + @TestMetadata("implicitInvokeOnSuper.kt") + public void testImplicitInvokeOnSuper() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.kt"); + doTest(fileName); + } + @TestMetadata("notAccessibleSuperInTrait.kt") public void testNotAccessibleSuperInTrait() throws Exception { runTest("compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index cd682a42a66..554acde89a9 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -20989,6 +20989,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.kt"); } + @TestMetadata("implicitInvokeOnSuper.kt") + public void testImplicitInvokeOnSuper() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/implicitInvokeOnSuper.kt"); + doTest(fileName); + } + @TestMetadata("notAccessibleSuperInTrait.kt") public void testNotAccessibleSuperInTrait() throws Exception { runTest("compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index b279df21dda..2f358789505 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -3274,6 +3274,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("anonymousObjectAsLastExpressionInLambda.kt") + public void testAnonymousObjectAsLastExpressionInLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt"); + doTest(fileName); + } + @TestMetadata("captureExtensionReceiver.kt") public void testCaptureExtensionReceiver() throws Exception { runTest("compiler/testData/codegen/box/closures/captureExtensionReceiver.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index d47dc789aea..57b5e8f565e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -3274,6 +3274,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("anonymousObjectAsLastExpressionInLambda.kt") + public void testAnonymousObjectAsLastExpressionInLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt"); + doTest(fileName); + } + @TestMetadata("captureExtensionReceiver.kt") public void testCaptureExtensionReceiver() throws Exception { runTest("compiler/testData/codegen/box/closures/captureExtensionReceiver.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 28819e296e4..f04e3ee698e 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 @@ -3189,6 +3189,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/closures"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("anonymousObjectAsLastExpressionInLambda.kt") + public void testAnonymousObjectAsLastExpressionInLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/closures/anonymousObjectAsLastExpressionInLambda.kt"); + doTest(fileName); + } + @TestMetadata("captureExtensionReceiver.kt") public void testCaptureExtensionReceiver() throws Exception { runTest("compiler/testData/codegen/box/closures/captureExtensionReceiver.kt");