Minor. Removed ReceiverValue.IRRELEVANT_RECEIVER.
This commit is contained in:
@@ -70,6 +70,20 @@ public class Visibilities {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This visibility is needed for the next case:
|
||||
* class A<in T>(t: T) {
|
||||
* private val t: T = t // visibility for t is PRIVATE_TO_THIS
|
||||
*
|
||||
* fun test() {
|
||||
* val x: T = t // correct
|
||||
* val y: T = this.t // also correct
|
||||
* }
|
||||
* fun foo(a: A<String>) {
|
||||
* val x: String = a.t // incorrect, because a.t can be Any
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public static final Visibility PRIVATE_TO_THIS = new Visibility("private_to_this", false) {
|
||||
@Override
|
||||
public boolean isVisible(@NotNull ReceiverValue thisObject, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
@@ -208,6 +222,14 @@ public class Visibilities {
|
||||
return findInvisibleMember(receiver, what, from) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receiver used only for visibility PRIVATE_TO_THIS.
|
||||
* For all other visibilities this method give correct result.
|
||||
*/
|
||||
public static boolean isVisibleWithIrrelevantReceiver(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
return findInvisibleMember(ReceiverValue.NO_RECEIVER /* temporary */, what, from) == null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DeclarationDescriptorWithVisibility findInvisibleMember(
|
||||
@NotNull ReceiverValue receiver,
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyAccessorDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.FlexibleTypesKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
@@ -297,7 +296,7 @@ public class OverridingUtil {
|
||||
for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
|
||||
OverrideCompatibilityInfo.Result result = DEFAULT.isOverridableBy(fromSupertype, fromCurrent, current).getResult();
|
||||
|
||||
boolean isVisible = Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, fromSupertype, current);
|
||||
boolean isVisible = Visibilities.isVisibleWithIrrelevantReceiver(fromSupertype, current);
|
||||
switch (result) {
|
||||
case OVERRIDABLE:
|
||||
if (isVisible) {
|
||||
@@ -485,7 +484,7 @@ public class OverridingUtil {
|
||||
public Boolean invoke(CallableMemberDescriptor descriptor) {
|
||||
//nested class could capture private member, so check for private visibility added
|
||||
return !Visibilities.isPrivate(descriptor.getVisibility()) &&
|
||||
Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, current);
|
||||
Visibilities.isVisibleWithIrrelevantReceiver(descriptor, current);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,24 +38,6 @@ public interface ReceiverValue extends Receiver {
|
||||
}
|
||||
};
|
||||
|
||||
ReceiverValue IRRELEVANT_RECEIVER = new ReceiverValue() {
|
||||
@NotNull
|
||||
@Override
|
||||
public KotlinType getType() {
|
||||
throw new UnsupportedOperationException("IRRELEVANT_RECEIVER.getType()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IRRELEVANT_RECEIVER";
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
KotlinType getType();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user