Make DynamicCallableDescriptors non static and remove static object DynamicType

This commit is contained in:
Pavel V. Talanov
2015-09-16 16:39:33 +03:00
parent 424d71e964
commit 6780a1fe90
4 changed files with 29 additions and 26 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.codeFragmentUtil.debugTypeInfo
import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.PossiblyBareType.type
import org.jetbrains.kotlin.resolve.TypeResolver.FlexibleTypeCapabilitiesProvider
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallableDescriptors
import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
@@ -49,7 +50,7 @@ public class TypeResolver(
private val storageManager: StorageManager,
private val lazinessToken: TypeLazinessToken,
private val dynamicTypesSettings: DynamicTypesSettings,
private val modifiersChecker: ModifiersChecker
private val dynamicCallableDescriptors: DynamicCallableDescriptors
) {
public open class FlexibleTypeCapabilitiesProvider {
@@ -243,7 +244,7 @@ public class TypeResolver(
}
override fun visitDynamicType(type: JetDynamicType) {
result = type(DynamicType)
result = type(dynamicCallableDescriptors.dynamicType)
if (!dynamicTypesSettings.dynamicTypesAllowed) {
c.trace.report(UNSUPPORTED.on(type, "Dynamic types are not supported in this context"))
}
@@ -53,7 +53,8 @@ import org.jetbrains.kotlin.types.isDynamic
public class TaskPrioritizer(
private val storageManager: StorageManager,
private val smartCastManager: SmartCastManager
private val smartCastManager: SmartCastManager,
private val dynamicCallableDescriptors: DynamicCallableDescriptors
) {
public fun <D : CallableDescriptor, F : D> computePrioritizedTasks(
@@ -234,7 +235,7 @@ public class TaskPrioritizer(
addExtensionCandidates(explicitReceiver, implicitReceivers, onlyDynamicReceivers, isExplicit)
c.result.addCandidates {
val dynamicScope = DynamicCallableDescriptors.createDynamicDescriptorScope(c.context.call, c.scope.ownerDescriptor)
val dynamicScope = dynamicCallableDescriptors.createDynamicDescriptorScope(c.context.call, c.scope.ownerDescriptor)
val dynamicDescriptors = c.callableDescriptorCollectors.flatMap {
it.getNonExtensionsByName(dynamicScope, c.name, createLookupLocation(c))
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.calls.tasks
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.*
@@ -31,17 +32,18 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.types.DynamicType
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.createDynamicType
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.types.isDynamic
import org.jetbrains.kotlin.utils.Printer
import java.util.ArrayList
import java.util.*
object DynamicCallableDescriptors {
class DynamicCallableDescriptors(private val builtIns: KotlinBuiltIns) {
val dynamicType = createDynamicType(builtIns)
@JvmStatic
fun createDynamicDescriptorScope(call: Call, owner: DeclarationDescriptor) = object : JetScopeImpl() {
override fun getContainingDeclaration() = owner
@@ -99,7 +101,7 @@ object DynamicCallableDescriptors {
/* isConst = */ false
)
propertyDescriptor.setType(
DynamicType,
dynamicType,
createTypeParameters(propertyDescriptor, call),
createDynamicDispatchReceiverParameter(propertyDescriptor),
null: JetType?
@@ -127,7 +129,7 @@ object DynamicCallableDescriptors {
createDynamicDispatchReceiverParameter(functionDescriptor),
createTypeParameters(functionDescriptor, call),
createValueParameters(functionDescriptor, call),
DynamicType,
dynamicType,
Modality.FINAL,
Visibilities.PUBLIC,
false,
@@ -137,7 +139,7 @@ object DynamicCallableDescriptors {
}
private fun createDynamicDispatchReceiverParameter(owner: CallableDescriptor): ReceiverParameterDescriptorImpl {
return ReceiverParameterDescriptorImpl(owner, TransientReceiver(DynamicType))
return ReceiverParameterDescriptorImpl(owner, TransientReceiver(dynamicType))
}
private fun createTypeParameters(owner: DeclarationDescriptor, call: Call): List<TypeParameterDescriptor> = call.getTypeArguments().indices.map {
@@ -175,10 +177,10 @@ object DynamicCallableDescriptors {
fun getFunctionType(funLiteralExpr: JetFunctionLiteralExpression): JetType {
val funLiteral = funLiteralExpr.getFunctionLiteral()
val receiverType = funLiteral.getReceiverTypeReference()?.let { DynamicType }
val parameterTypes = funLiteral.getValueParameters().map { DynamicType }
val receiverType = funLiteral.getReceiverTypeReference()?.let { dynamicType }
val parameterTypes = funLiteral.getValueParameters().map { dynamicType }
return owner.builtIns.getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, DynamicType)
return owner.builtIns.getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, dynamicType)
}
for (arg in call.getValueArguments()) {
@@ -196,12 +198,12 @@ object DynamicCallableDescriptors {
arg.getSpreadElement() != null -> {
hasSpreadOperator = true
outType = owner.builtIns.getArrayType(Variance.OUT_VARIANCE, DynamicType)
varargElementType = DynamicType
outType = owner.builtIns.getArrayType(Variance.OUT_VARIANCE, dynamicType)
varargElementType = dynamicType
}
else -> {
outType = DynamicType
outType = dynamicType
varargElementType = null
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.types.typeUtil.builtIns
open class DynamicTypesSettings {
open val dynamicTypesAllowed: Boolean
@@ -30,16 +31,14 @@ class DynamicTypesAllowed: DynamicTypesSettings() {
interface Dynamicity : TypeCapability
// Object is created only for convenience here. Dynamic types may occur in the form of DelegatingFlexibleTypes,
// which are produced by substitutions
object DynamicType : DelegatingFlexibleType(
KotlinBuiltIns.getInstance().getNothingType(),
KotlinBuiltIns.getInstance().getNullableAnyType(),
DynamicTypeCapabilities
)
fun JetType.isDynamic(): Boolean = this.getCapability(javaClass<Dynamicity>()) != null
fun createDynamicType(builtIns: KotlinBuiltIns) = object : DelegatingFlexibleType(
builtIns.nothingType,
builtIns.nullableAnyType,
DynamicTypeCapabilities
) {}
public object DynamicTypeCapabilities : FlexibleTypeCapabilities {
override val id: String get() = "kotlin.DynamicType"
@@ -66,7 +65,7 @@ public object DynamicTypeCapabilities : FlexibleTypeCapabilities {
override fun makeNullableAsSpecified(nullable: Boolean): JetType {
// Nullability has no effect on dynamics
return DynamicType
return createDynamicType(delegateType.builtIns)
}
override fun computeIsNullable() = false