Introduce original for ReceiverValue and use it inside coroutine checker

This commit is contained in:
Mikhail Zarechenskiy
2018-05-04 18:40:21 +03:00
parent b23e9f771b
commit 54ca2cbbe0
13 changed files with 88 additions and 41 deletions
@@ -402,6 +402,12 @@ public class Visibilities {
public ReceiverValue replaceType(@NotNull KotlinType newType) {
throw new IllegalStateException("This method should not be called");
}
@NotNull
@Override
public ReceiverValue getOriginal() {
return this;
}
};
/**
@@ -420,6 +426,12 @@ public class Visibilities {
public ReceiverValue replaceType(@NotNull KotlinType newType) {
throw new IllegalStateException("This method should not be called");
}
@NotNull
@Override
public ReceiverValue getOriginal() {
return this;
}
};
// This constant is not intended to use somewhere else from
@@ -436,6 +448,12 @@ public class Visibilities {
public ReceiverValue replaceType(@NotNull KotlinType newType) {
throw new IllegalStateException("This method should not be called");
}
@NotNull
@Override
public ReceiverValue getOriginal() {
return this;
}
};
public static boolean isPrivate(@NotNull Visibility visibility) {
@@ -28,7 +28,7 @@ public class LazyClassReceiverParameterDescriptor extends AbstractReceiverParame
public LazyClassReceiverParameterDescriptor(@NotNull ClassDescriptor descriptor) {
this.descriptor = descriptor;
this.receiverValue = new ImplicitClassReceiver(descriptor);
this.receiverValue = new ImplicitClassReceiver(descriptor, null);
}
@NotNull
@@ -159,6 +159,6 @@ public class DescriptorFactory {
) {
return receiverParameterType == null
? null
: new ReceiverParameterDescriptorImpl(owner, new ExtensionReceiver(owner, receiverParameterType));
: new ReceiverParameterDescriptorImpl(owner, new ExtensionReceiver(owner, receiverParameterType, null));
}
}
@@ -17,13 +17,16 @@
package org.jetbrains.kotlin.resolve.scopes.receivers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.types.KotlinType;
public abstract class AbstractReceiverValue implements ReceiverValue {
protected final KotlinType receiverType;
private final ReceiverValue original;
public AbstractReceiverValue(@NotNull KotlinType receiverType) {
public AbstractReceiverValue(@NotNull KotlinType receiverType, @Nullable ReceiverValue original) {
this.receiverType = receiverType;
this.original = original != null ? original : this;
}
@Override
@@ -31,4 +34,10 @@ public abstract class AbstractReceiverValue implements ReceiverValue {
public KotlinType getType() {
return receiverType;
}
@NotNull
@Override
public ReceiverValue getOriginal() {
return original;
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.scopes.receivers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.types.KotlinType;
@@ -24,8 +25,12 @@ public class ExtensionReceiver extends AbstractReceiverValue implements Implicit
private final CallableDescriptor descriptor;
public ExtensionReceiver(@NotNull CallableDescriptor callableDescriptor, @NotNull KotlinType receiverType) {
super(receiverType);
public ExtensionReceiver(
@NotNull CallableDescriptor callableDescriptor,
@NotNull KotlinType receiverType,
@Nullable ReceiverValue original
) {
super(receiverType, original);
this.descriptor = callableDescriptor;
}
@@ -38,7 +43,7 @@ public class ExtensionReceiver extends AbstractReceiverValue implements Implicit
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
return new ExtensionReceiver(descriptor, newType);
return new ExtensionReceiver(descriptor, newType, getOriginal());
}
@Override
@@ -30,7 +30,12 @@ interface ThisClassReceiver : ReceiverValue {
/**
* Same but implicit only
*/
open class ImplicitClassReceiver(final override val classDescriptor: ClassDescriptor) : ThisClassReceiver, ImplicitReceiver {
open class ImplicitClassReceiver(
final override val classDescriptor: ClassDescriptor,
original: ImplicitClassReceiver? = null
) : ThisClassReceiver, ImplicitReceiver {
private val original = original ?: this
override fun getType() = classDescriptor.defaultType
@@ -44,4 +49,6 @@ open class ImplicitClassReceiver(final override val classDescriptor: ClassDescri
override fun replaceType(newType: KotlinType) =
throw UnsupportedOperationException("Replace type should not be called for this receiver")
override fun getOriginal() = original
}
@@ -26,4 +26,7 @@ public interface ReceiverValue extends Receiver {
@NotNull
ReceiverValue replaceType(@NotNull KotlinType newType);
@NotNull
ReceiverValue getOriginal();
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.scopes.receivers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.types.KotlinType;
/**
@@ -25,7 +26,11 @@ import org.jetbrains.kotlin.types.KotlinType;
*/
public class TransientReceiver extends AbstractReceiverValue {
public TransientReceiver(@NotNull KotlinType type) {
super(type);
this(type, null);
}
private TransientReceiver(@NotNull KotlinType type, @Nullable ReceiverValue original) {
super(type, original);
}
@Override
@@ -36,6 +41,6 @@ public class TransientReceiver extends AbstractReceiverValue {
@NotNull
@Override
public ReceiverValue replaceType(@NotNull KotlinType newType) {
return new TransientReceiver(newType);
return new TransientReceiver(newType, getOriginal());
}
}