Moved logic for PRIVATE_TO_THIS visibility from ExpressionTypingUtils.normalizeReceiverValueForVisibility to ExpressionReceiver.create
This commit is contained in:
@@ -420,8 +420,7 @@ public class JetFlowInformationProvider {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = CallUtilKt.getResolvedCall(expression, trace.getBindingContext());
|
||||
ReceiverValue receiverValue = ReceiverValue.IRRELEVANT_RECEIVER;
|
||||
if (resolvedCall != null) {
|
||||
receiverValue = ExpressionTypingUtils
|
||||
.normalizeReceiverValueForVisibility(resolvedCall.getDispatchReceiver(), trace.getBindingContext());
|
||||
receiverValue = resolvedCall.getDispatchReceiver();
|
||||
|
||||
}
|
||||
if (Visibilities.isVisible(receiverValue, variableDescriptor, descriptor) && setterDescriptor != null
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.TypeUtils.noExpectedType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
import java.util.*
|
||||
|
||||
public class CandidateResolver(
|
||||
@@ -169,9 +168,7 @@ public class CandidateResolver(
|
||||
}
|
||||
|
||||
private fun CallCandidateResolutionContext<*>.checkVisibility() = checkAndReport {
|
||||
val receiverValue = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidateCall.getDispatchReceiver(),
|
||||
trace.getBindingContext())
|
||||
val invisibleMember = Visibilities.findInvisibleMember(receiverValue, candidateDescriptor, scope.ownerDescriptor)
|
||||
val invisibleMember = Visibilities.findInvisibleMember(candidateCall.dispatchReceiver, candidateDescriptor, scope.ownerDescriptor)
|
||||
if (invisibleMember != null) {
|
||||
tracing.invisibleMember(trace, invisibleMember)
|
||||
OTHER_ERROR
|
||||
|
||||
@@ -235,7 +235,7 @@ public class TaskPrioritizer(
|
||||
|
||||
val dispatchReceiver =
|
||||
if (explicitReceiver.value is ClassReceiver && type != explicitReceiver.value.type) {
|
||||
CastClassReceiver(explicitReceiver.value.declarationDescriptor, type)
|
||||
CastClassReceiver(explicitReceiver.value.classDescriptor, type)
|
||||
}
|
||||
else {
|
||||
explicitReceiver.value
|
||||
@@ -485,8 +485,7 @@ public class TaskPrioritizer(
|
||||
if (candidate == null) return false
|
||||
val candidateDescriptor = candidate.getDescriptor()
|
||||
if (ErrorUtils.isError(candidateDescriptor)) return true
|
||||
val receiverValue = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidate.getDispatchReceiver(), context.trace.getBindingContext())
|
||||
return Visibilities.isVisible(receiverValue, candidateDescriptor, context.scope.ownerDescriptor)
|
||||
return Visibilities.isVisible(candidate.dispatchReceiver, candidateDescriptor, context.scope.ownerDescriptor)
|
||||
}
|
||||
|
||||
private fun hasLowPriority(candidate: ResolutionCandidate<D>?): Boolean {
|
||||
|
||||
+26
-1
@@ -16,7 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.scopes.receivers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
@@ -24,17 +28,38 @@ interface ExpressionReceiver : ReceiverValue {
|
||||
val expression: KtExpression
|
||||
|
||||
companion object {
|
||||
class ExpressionReceiverImpl(
|
||||
open class ExpressionReceiverImpl(
|
||||
override val expression: KtExpression, type: KotlinType
|
||||
): AbstractReceiverValue(type), ExpressionReceiver {
|
||||
override fun toString() = "$type {$expression: ${expression.text}}"
|
||||
}
|
||||
|
||||
private class ThisExpressionClassReceiver(
|
||||
override val classDescriptor: ClassDescriptor,
|
||||
expression: KtExpression,
|
||||
type: KotlinType
|
||||
) : ExpressionReceiverImpl(expression, type), ExpressionOrImplicitClassReceiver
|
||||
|
||||
fun create(
|
||||
expression: KtExpression,
|
||||
type: KotlinType,
|
||||
bindingContext: BindingContext
|
||||
): ExpressionReceiver {
|
||||
var referenceExpression: KtReferenceExpression? = null
|
||||
if (expression is KtThisExpression) {
|
||||
referenceExpression = expression.instanceReference
|
||||
}
|
||||
else if (expression is KtConstructorDelegationReferenceExpression) { // todo check this
|
||||
referenceExpression = expression
|
||||
}
|
||||
|
||||
if (referenceExpression != null) {
|
||||
val descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, referenceExpression)
|
||||
if (descriptor is ClassDescriptor) {
|
||||
return ThisExpressionClassReceiver(descriptor.original as ClassDescriptor, expression, type)
|
||||
}
|
||||
}
|
||||
|
||||
return ExpressionReceiverImpl(expression, type)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-25
@@ -31,12 +31,13 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.resolve.ObservableBindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.TraceBasedRedeclarationHandler;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryKt;
|
||||
@@ -49,28 +50,6 @@ import static org.jetbrains.kotlin.resolve.BindingContext.PROCESSED;
|
||||
|
||||
public class ExpressionTypingUtils {
|
||||
|
||||
@NotNull
|
||||
public static ReceiverValue normalizeReceiverValueForVisibility(@NotNull ReceiverValue receiverValue, @NotNull BindingContext trace) {
|
||||
if (receiverValue instanceof ExpressionReceiver) {
|
||||
KtExpression expression = ((ExpressionReceiver) receiverValue).getExpression();
|
||||
KtReferenceExpression referenceExpression = null;
|
||||
if (expression instanceof KtThisExpression) {
|
||||
referenceExpression = ((KtThisExpression) expression).getInstanceReference();
|
||||
}
|
||||
else if (expression instanceof KtConstructorDelegationReferenceExpression) {
|
||||
referenceExpression = (KtReferenceExpression) expression;
|
||||
}
|
||||
|
||||
if (referenceExpression != null) {
|
||||
DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, referenceExpression);
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
return new ClassReceiver((ClassDescriptor) descriptor.getOriginal());
|
||||
}
|
||||
}
|
||||
}
|
||||
return receiverValue;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ExpressionReceiver getExpressionReceiver(
|
||||
@NotNull ExpressionTypingFacade facade,
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
import java.util.*
|
||||
|
||||
@@ -136,8 +135,7 @@ public fun Call.resolveCandidates(
|
||||
|
||||
if (filterOutByVisibility) {
|
||||
candidates = candidates.filter {
|
||||
val thisReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(it.dispatchReceiver, bindingContext)
|
||||
Visibilities.isVisible(thisReceiver, it.resultingDescriptor, inDescriptor)
|
||||
Visibilities.isVisible(it.dispatchReceiver, it.resultingDescriptor, inDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
|
||||
fun DeclarationDescriptorWithVisibility.isVisible(
|
||||
from: DeclarationDescriptor,
|
||||
@@ -47,15 +46,13 @@ fun DeclarationDescriptorWithVisibility.isVisible(
|
||||
val explicitReceiver = type?.let { ExpressionReceiver.create(receiver!!, it, bindingContext) }
|
||||
|
||||
if (explicitReceiver != null) {
|
||||
val normalizeReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(explicitReceiver, bindingContext)
|
||||
return Visibilities.isVisible(normalizeReceiver, this, from)
|
||||
return Visibilities.isVisible(explicitReceiver, this, from)
|
||||
}
|
||||
|
||||
val resolutionScope = element.getResolutionScope(bindingContext, element.getResolutionFacade())
|
||||
val implicitReceivers = resolutionScope.getImplicitReceiversHierarchy()
|
||||
for (implicitReceiver in implicitReceivers) {
|
||||
val normalizeReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(implicitReceiver.getValue(), bindingContext)
|
||||
if (Visibilities.isVisible(normalizeReceiver, this, from)) return true
|
||||
if (Visibilities.isVisible(implicitReceiver.value, this, from)) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user