Refactoring. Change type of ResolvedCall#extensionReceiver from Receiver to ReceiverValue
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1402,7 +1402,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
//noinspection EnumSwitchStatementWhichMissesCases
|
||||
when (kind) {
|
||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> explicitReceiver = resolvedCall.dispatchReceiver
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> explicitReceiver = resolvedCall.extensionReceiver as ReceiverValue?
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> explicitReceiver = resolvedCall.extensionReceiver
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> {}
|
||||
}
|
||||
}
|
||||
@@ -1413,7 +1413,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
}
|
||||
val callElement = resolvedCall.call.callElement
|
||||
receiverValues = getReceiverValues(callElement, resolvedCall.dispatchReceiver, receiverValues)
|
||||
receiverValues = getReceiverValues(callElement, resolvedCall.extensionReceiver as ReceiverValue?, receiverValues)
|
||||
receiverValues = getReceiverValues(callElement, resolvedCall.extensionReceiver, receiverValues)
|
||||
return receiverValues
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -214,7 +213,7 @@ class CallCompleter(
|
||||
return
|
||||
}
|
||||
|
||||
val receiverType = (extensionReceiver as? ReceiverValue)?.type
|
||||
val receiverType = extensionReceiver?.type
|
||||
|
||||
val errorData = InferenceErrorData.create(
|
||||
candidateDescriptor, constraintSystem!!, valueArgumentsCheckingResult.argumentTypes,
|
||||
|
||||
@@ -452,7 +452,7 @@ class CandidateResolver(
|
||||
resultStatus = resultStatus.combine(context.checkReceiver(
|
||||
candidateCall,
|
||||
candidateCall.getResultingDescriptor().extensionReceiverParameter,
|
||||
candidateCall.extensionReceiver as ReceiverValue?,
|
||||
candidateCall.extensionReceiver,
|
||||
candidateCall.explicitReceiverKind.isExtensionReceiver,
|
||||
implicitInvokeCheck = false, isDispatchReceiver = false))
|
||||
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.INCOMPLETE_TY
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.OTHER_ERROR
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
@@ -79,7 +78,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
||||
val receiverArgument = candidateCall.extensionReceiver
|
||||
val receiverParameter = candidate.extensionReceiverParameter
|
||||
if (receiverArgument != null && receiverParameter != null) {
|
||||
val receiverArgumentType = (receiverArgument as ReceiverValue).type
|
||||
val receiverArgumentType = receiverArgument.type
|
||||
var receiverType: KotlinType? = if (context.candidateCall.isSafeCall)
|
||||
TypeUtils.makeNotNullable(receiverArgumentType)
|
||||
else
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ class InlineChecker implements CallChecker {
|
||||
//checking that only invoke or inlinable extension called on function parameter
|
||||
CallableDescriptor targetDescriptor = resolvedCall.getResultingDescriptor();
|
||||
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getDispatchReceiver(), expression);
|
||||
checkCallWithReceiver(context, targetDescriptor, (ReceiverValue) resolvedCall.getExtensionReceiver(), expression);
|
||||
checkCallWithReceiver(context, targetDescriptor, resolvedCall.getExtensionReceiver(), expression);
|
||||
|
||||
if (inlinableParameters.contains(targetDescriptor)) {
|
||||
if (!isInsideCall(expression)) {
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.psi.Call;
|
||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
@@ -65,7 +64,7 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Receiver getExtensionReceiver() {
|
||||
public ReceiverValue getExtensionReceiver() {
|
||||
return resolvedCall.getExtensionReceiver();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.psi.Call;
|
||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
@@ -50,7 +49,7 @@ public interface ResolvedCall<D extends CallableDescriptor> {
|
||||
|
||||
/** If the target was an extension function or property, this is the value for its receiver parameter */
|
||||
@Nullable
|
||||
Receiver getExtensionReceiver();
|
||||
ReceiverValue getExtensionReceiver();
|
||||
|
||||
/** If the target was a member of a class, this is the object of that class to call it on */
|
||||
@Nullable
|
||||
|
||||
+2
-3
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeProjection;
|
||||
@@ -77,7 +76,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
||||
private final D candidateDescriptor;
|
||||
private D resultingDescriptor; // Probably substituted
|
||||
private final ReceiverValue dispatchReceiver; // receiver object of a method
|
||||
private final Receiver extensionReceiver; // receiver of an extension function
|
||||
private final ReceiverValue extensionReceiver; // receiver of an extension function
|
||||
private final ExplicitReceiverKind explicitReceiverKind;
|
||||
private final TypeSubstitutor knownTypeParametersSubstitutor;
|
||||
|
||||
@@ -275,7 +274,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Receiver getExtensionReceiver() {
|
||||
public ReceiverValue getExtensionReceiver() {
|
||||
return extensionReceiver;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,15 +63,15 @@ fun ResolvedCall<*>.hasThisOrNoDispatchReceiver(
|
||||
fun ResolvedCall<*>.getExplicitReceiverValue(): ReceiverValue? {
|
||||
return when (explicitReceiverKind) {
|
||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> dispatchReceiver!!
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> extensionReceiver as ReceiverValue
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER, ExplicitReceiverKind.BOTH_RECEIVERS -> extensionReceiver!!
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun ResolvedCall<*>.getImplicitReceiverValue(): ReceiverValue? {
|
||||
return when (explicitReceiverKind) {
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> if (extensionReceiver != null) extensionReceiver as ReceiverValue else dispatchReceiver
|
||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver as ReceiverValue?
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> extensionReceiver ?: dispatchReceiver
|
||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER -> dispatchReceiver
|
||||
else -> null
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.constants.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
@@ -860,7 +859,7 @@ fun isIntegerType(value: Any?) = value is Byte || value is Short || value is Int
|
||||
private fun getReceiverExpressionType(resolvedCall: ResolvedCall<*>): KotlinType? {
|
||||
return when (resolvedCall.explicitReceiverKind) {
|
||||
ExplicitReceiverKind.DISPATCH_RECEIVER -> resolvedCall.dispatchReceiver!!.type
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER -> (resolvedCall.extensionReceiver as ReceiverValue).type
|
||||
ExplicitReceiverKind.EXTENSION_RECEIVER -> resolvedCall.extensionReceiver!!.type
|
||||
ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> null
|
||||
ExplicitReceiverKind.BOTH_RECEIVERS -> null
|
||||
else -> null
|
||||
|
||||
Reference in New Issue
Block a user