diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java index fd6f0a438cc..b8c20928838 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.config.LanguageFeature; import org.jetbrains.kotlin.config.LanguageVersionSettings; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; -import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl; import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus; @@ -46,7 +45,6 @@ import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.KotlinTypeKt; -import org.jetbrains.kotlin.types.TypeSubstitutor; import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext; import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices; import org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher; @@ -293,23 +291,17 @@ public class CallResolver { } @NotNull - public OverloadResolutionResults resolveCallWithGivenDescriptor( + public OverloadResolutionResults resolveThisOrSuperCallWithGivenDescriptor( @NotNull ExpressionTypingContext context, @NotNull Call call, - @NotNull D descriptor, - @NotNull TracingStrategy tracingStrategy, - @Nullable TypeSubstitutor substitutor, - @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments + @NotNull ReceiverParameterDescriptor descriptor ) { - BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create( - context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments - ); + BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS); return PSICallResolver.runResolutionAndInferenceForGivenDescriptors( callResolutionContext, Collections.singletonList(descriptor), - tracingStrategy, - substitutor + TracingStrategy.EMPTY ); } @@ -588,6 +580,27 @@ public class CallResolver { return false; } + public OverloadResolutionResults resolveCallWithKnownCandidate( + @NotNull Call call, + @NotNull TracingStrategy tracing, + @NotNull ResolutionContext context, + @NotNull OldResolutionCandidate candidate, + @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments + ) { + return callResolvePerfCounter.>time(() -> { + BasicCallResolutionContext basicCallResolutionContext = + BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments); + + Set> candidates = Collections.singleton(candidate); + + ResolutionTask resolutionTask = new ResolutionTask<>( + new NewResolutionOldInference.ResolutionKind.GivenCandidates(), null, candidates + ); + + return doResolveCallOrGetCachedResults(basicCallResolutionContext, resolutionTask, tracing); + }); + } + private OverloadResolutionResults doResolveCallOrGetCachedResults( @NotNull BasicCallResolutionContext context, @NotNull ResolutionTask resolutionTask, 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 2429abf4679..7662897b165 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 @@ -147,8 +147,7 @@ class PSICallResolver( fun runResolutionAndInferenceForGivenDescriptors( context: BasicCallResolutionContext, descriptors: Collection, - tracingStrategy: TracingStrategy, - substitutor: TypeSubstitutor? = null + tracingStrategy: TracingStrategy ): OverloadResolutionResults { val isSpecialFunction = descriptors.any { it.name in SPECIAL_FUNCTION_NAMES } val kotlinCall = toKotlinCall( @@ -160,7 +159,7 @@ class PSICallResolver( GivenCandidate( it, dispatchReceiver = null, - knownTypeParametersResultingSubstitutor = substitutor + knownTypeParametersResultingSubstitutor = null ) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt index 6d6c061c50d..6c32d8c0c29 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt @@ -149,7 +149,7 @@ fun KtElement.getCall(context: BindingContext): Call? { else -> element.getCalleeExpressionIfAny() } if (reference != null) { - return context[CALL, reference] ?: context[CALL, element] + return context[CALL, reference] } return context[CALL, element] } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 9d0ba324bf7..6053dba0198 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -636,7 +636,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { BindingTrace trace = context.trace; Call call = CallMaker.makeCall(expression, null, null, expression, Collections.emptyList()); OverloadResolutionResults results = - components.callResolver.resolveCallWithGivenDescriptor(context, call, descriptor, TracingStrategy.EMPTY, null, null); + components.callResolver.resolveThisOrSuperCallWithGivenDescriptor(context, call, descriptor); ResolvedCall resolvedCall = results.getResultingCall(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java index 2d10acd1c8d..66f772d665f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java @@ -49,6 +49,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind; +import org.jetbrains.kotlin.resolve.calls.tasks.OldResolutionCandidate; import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy; import org.jetbrains.kotlin.resolve.calls.util.CallMaker; import org.jetbrains.kotlin.resolve.descriptorUtil.AnnotationsForResolveUtilsKt; @@ -161,17 +162,12 @@ public class ControlStructureTypingUtils { ) { TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context); TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType, context.languageVersionSettings); - OverloadResolutionResults results = callResolver.resolveCallWithGivenDescriptor( - context, call, function, tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments - ); + OldResolutionCandidate resolutionCandidate = + OldResolutionCandidate.create(call, function, knownTypeParameterSubstitutor); + OverloadResolutionResults results = callResolver.resolveCallWithKnownCandidate( + call, tracing, context, resolutionCandidate, dataFlowInfoForArguments); assert results.isSingleResult() : "Not single result after resolving one known candidate"; - - ResolvedCall resolvedCall = results.getResultingCall(); - - context.trace.record(RESOLVED_CALL, call, resolvedCall); - context.trace.record(CALL, call.getCallElement(), call); - - return resolvedCall; + return results.getResultingCall(); } private static @Nullable TypeSubstitutor createKnownTypeParameterSubstitutorForSpecialCall( diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt index 2fa381988e2..f938bcafd34 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.kt @@ -9,8 +9,8 @@ class A(outer: Outer) { var g: String by outer.getContainer().getMyProperty() - var b: String by foo(getMyProperty()) - var r: String by foo(outer.getContainer().getMyProperty()) + var b: String by foo(getMyProperty()) + var r: String by foo(outer.getContainer().getMyProperty()) var e: String by + foo(getMyProperty()) var f: String by foo(getMyProperty()) - 1 } diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt index 915ace3e5b5..462d4c0511f 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.kt @@ -7,7 +7,7 @@ class A() { operator fun setValue(t: Any?, p: KProperty<*>, x: T) = Unit } -var a1: Int by A() +var a1: Int by A() var a2: Int by A() class B() { @@ -24,4 +24,4 @@ class C() { } var c1: Int by C() -var c2: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt index 3d7cd08196f..dd4bb974523 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt @@ -3,7 +3,7 @@ import kotlin.reflect.KProperty var a: Int by A() -var a1 by A() +var a1 by A() var b: Int by B() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt index 7244e5d2b77..e1eadab0b52 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisOfNothingType.kt @@ -6,7 +6,7 @@ class A { var a: Int by Delegate() } -var aTopLevel: Int by Delegate() +var aTopLevel: Int by Delegate() class Delegate { fun getValue(t: Nothing, p: KProperty<*>): Int { diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt deleted file mode 100644 index 2ca56509138..00000000000 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt +++ /dev/null @@ -1,23 +0,0 @@ -// FILE: J.java - -import org.jetbrains.annotations.*; - -public class J { - - public interface DP { - String getValue(Object a, Object b); - String setValue(Object a, Object b, Object c); - } - - @NotNull - public static DP staticNN; - @Nullable - public static DP staticN; - public static DP staticJ; -} - -// FILE: k.kt - -var A by J.staticNN -var B by J.staticN -var C by J.staticJ diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt index 676ce3580b8..75361e7bd2e 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: J.java import org.jetbrains.annotations.*; @@ -19,5 +20,5 @@ public class J { // FILE: k.kt var A by J.staticNN -var B by J.staticN +var B by J.staticN var C by J.staticJ