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 b8c20928838..fd6f0a438cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -17,6 +17,7 @@ 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; @@ -45,6 +46,7 @@ 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; @@ -291,17 +293,23 @@ public class CallResolver { } @NotNull - public OverloadResolutionResults resolveThisOrSuperCallWithGivenDescriptor( + public OverloadResolutionResults resolveCallWithGivenDescriptor( @NotNull ExpressionTypingContext context, @NotNull Call call, - @NotNull ReceiverParameterDescriptor descriptor + @NotNull D descriptor, + @NotNull TracingStrategy tracingStrategy, + @Nullable TypeSubstitutor substitutor, + @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments ) { - BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS); + BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create( + context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments + ); return PSICallResolver.runResolutionAndInferenceForGivenDescriptors( callResolutionContext, Collections.singletonList(descriptor), - TracingStrategy.EMPTY + tracingStrategy, + substitutor ); } @@ -580,27 +588,6 @@ 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 bdf3cb08ad9..971f23e2fbd 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 @@ -146,7 +146,8 @@ class PSICallResolver( fun runResolutionAndInferenceForGivenDescriptors( context: BasicCallResolutionContext, descriptors: Collection, - tracingStrategy: TracingStrategy + tracingStrategy: TracingStrategy, + substitutor: TypeSubstitutor? = null ): OverloadResolutionResults { val isSpecialFunction = descriptors.any { it.name in SPECIAL_FUNCTION_NAMES } val kotlinCall = toKotlinCall( @@ -158,7 +159,7 @@ class PSICallResolver( GivenCandidate( it, dispatchReceiver = null, - knownTypeParametersResultingSubstitutor = null + knownTypeParametersResultingSubstitutor = substitutor ) } 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 ed89eded371..f6b9096fdfe 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 @@ -171,7 +171,7 @@ fun KtElement.getCall(context: BindingContext): Call? { else -> element.getCalleeExpressionIfAny() } if (reference != null) { - return context[CALL, reference] + return context[CALL, reference] ?: context[CALL, element] } 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 6053dba0198..9d0ba324bf7 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.resolveThisOrSuperCallWithGivenDescriptor(context, call, descriptor); + components.callResolver.resolveCallWithGivenDescriptor(context, call, descriptor, TracingStrategy.EMPTY, null, null); 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 66f772d665f..2d10acd1c8d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java @@ -49,7 +49,6 @@ 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; @@ -162,12 +161,17 @@ public class ControlStructureTypingUtils { ) { TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context); TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType, context.languageVersionSettings); - OldResolutionCandidate resolutionCandidate = - OldResolutionCandidate.create(call, function, knownTypeParameterSubstitutor); - OverloadResolutionResults results = callResolver.resolveCallWithKnownCandidate( - call, tracing, context, resolutionCandidate, dataFlowInfoForArguments); + OverloadResolutionResults results = callResolver.resolveCallWithGivenDescriptor( + context, call, function, tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments + ); assert results.isSingleResult() : "Not single result after resolving one known candidate"; - return results.getResultingCall(); + + ResolvedCall resolvedCall = results.getResultingCall(); + + context.trace.record(RESOLVED_CALL, call, resolvedCall); + context.trace.record(CALL, call.getCallElement(), call); + + return resolvedCall; } 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 f938bcafd34..2fa381988e2 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 462d4c0511f..915ace3e5b5 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 dd4bb974523..3d7cd08196f 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 e1eadab0b52..7244e5d2b77 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 new file mode 100644 index 00000000000..2ca56509138 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.fir.kt @@ -0,0 +1,23 @@ +// 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 75361e7bd2e..676ce3580b8 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/delegatedProperties.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // FILE: J.java import org.jetbrains.annotations.*; @@ -20,5 +19,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