[FE] Resolve overload conflict between contextual and non-contextual declarations

This commit is contained in:
Anastasiya Shadrina
2021-06-30 19:07:26 +07:00
committed by TeamCityServer
parent 7fd5034cd6
commit f427265739
12 changed files with 267 additions and 125 deletions
@@ -27,6 +27,7 @@ fun <T> FlatSignature.Companion.createFromReflectionType(
// Plus, currently, receiver for reflection type is taking from *candidate*, see buildReflectionType, this candidate can
// have transient receiver which is not the same in its signature
val receiver = descriptor.extensionReceiverParameter?.type
val contextReceiversTypes = descriptor.contextReceiverParameters.mapNotNull { it.type }
val parameters = reflectionType.getValueParameterTypesFromCallableReflectionType(
receiver != null && !hasBoundExtensionReceiver
).map { it.type }
@@ -34,8 +35,9 @@ fun <T> FlatSignature.Companion.createFromReflectionType(
return FlatSignature(
origin,
descriptor.typeParameters,
listOfNotNull(receiver) + parameters,
contextReceiversTypes + listOfNotNull(receiver) + parameters,
hasExtensionReceiver = receiver != null,
contextReceiverCount = contextReceiversTypes.size,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = numDefaults,
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
@@ -52,12 +54,14 @@ fun <T> FlatSignature.Companion.create(
parameterTypes: List<TypeWithConversion?>,
): FlatSignature<T> {
val extensionReceiverType = descriptor.extensionReceiverParameter?.type
val contextReceiverTypes = descriptor.contextReceiverParameters.mapNotNull { TypeWithConversion(it.type) }
return FlatSignature(
origin,
descriptor.typeParameters,
valueParameterTypes = extensionReceiverType?.let { listOf(TypeWithConversion(it)) }.orEmpty() + parameterTypes,
valueParameterTypes = contextReceiverTypes + extensionReceiverType?.let { listOf(TypeWithConversion(it)) }.orEmpty() + parameterTypes,
hasExtensionReceiver = extensionReceiverType != null,
contextReceiverCount = contextReceiverTypes.size,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = numDefaults,
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
@@ -72,12 +76,14 @@ fun <T> FlatSignature.Companion.create(
parameterTypes: List<KotlinType?>
): FlatSignature<T> {
val extensionReceiverType = descriptor.extensionReceiverParameter?.type
val contextReceiverTypes = descriptor.contextReceiverParameters.mapNotNull { it.type }
return FlatSignature(
origin,
descriptor.typeParameters,
valueParameterTypes = listOfNotNull(extensionReceiverType) + parameterTypes,
valueParameterTypes = contextReceiverTypes + listOfNotNull(extensionReceiverType) + parameterTypes,
hasExtensionReceiver = extensionReceiverType != null,
contextReceiverCount = contextReceiverTypes.size,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = numDefaults,
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
@@ -89,9 +95,11 @@ fun <D : CallableDescriptor> FlatSignature.Companion.createFromCallableDescripto
FlatSignature(
descriptor,
descriptor.typeParameters,
valueParameterTypes = listOfNotNull(descriptor.extensionReceiverParameter?.type)
valueParameterTypes = descriptor.contextReceiverParameters.map { it.type }
+ listOfNotNull(descriptor.extensionReceiverParameter?.type)
+ descriptor.valueParameters.map { it.argumentValueType },
hasExtensionReceiver = descriptor.extensionReceiverParameter?.type != null,
contextReceiverCount = descriptor.contextReceiverParameters.size,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = 0,
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
@@ -104,6 +112,7 @@ fun <D : CallableDescriptor> FlatSignature.Companion.createForPossiblyShadowedEx
descriptor.typeParameters,
valueParameterTypes = descriptor.valueParameters.map { it.argumentValueType },
hasExtensionReceiver = false,
contextReceiverCount = 0,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = descriptor.valueParameters.count { it.hasDefaultValue() },
isExpect = descriptor is MemberDescriptor && descriptor.isExpect,
@@ -310,6 +310,9 @@ open class OverloadingConflictResolver<C : Any>(
if (!call1.isExpect && call2.isExpect) return true
if (call1.isExpect && !call2.isExpect) return false
if (call1.contextReceiverCount > call2.contextReceiverCount) return true
if (call1.contextReceiverCount < call2.contextReceiverCount) return false
return createEmptyConstraintSystem().isSignatureNotLessSpecific(
call1,
call2,