Discriminate 'platform' declarations in resolution

Otherwise calls to functions which are declared twice (platform and impl) would
result in an error "conflicting overloads" in platform-specific modules
This commit is contained in:
Alexander Udalov
2016-11-17 14:52:43 +03:00
parent 926b81fb35
commit a3cfd3962c
3 changed files with 12 additions and 4 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.calls.results
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.psi.ValueArgument
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
@@ -55,7 +56,8 @@ fun <RC : ResolvedCall<*>> RC.createFlatSignature(): FlatSignature<RC> {
call.valueArguments.map { valueArgumentToParameterType[it] },
hasExtensionReceiver = originalDescriptor.extensionReceiverParameter != null,
hasVarargs = originalDescriptor.valueParameters.any { it.varargElementType != null },
numDefaults = numDefaults)
numDefaults = numDefaults,
isPlatform = originalDescriptor is MemberDescriptor && originalDescriptor.isPlatform)
}
fun createOverloadingConflictResolver(
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.calls.results
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.types.*
@@ -41,7 +42,8 @@ class FlatSignature<out T>(
val valueParameterTypes: List<KotlinType?>,
val hasExtensionReceiver: Boolean,
val hasVarargs: Boolean,
val numDefaults: Int
val numDefaults: Int,
val isPlatform: Boolean
) {
val isGeneric = typeParameters.isNotEmpty()
@@ -52,7 +54,8 @@ class FlatSignature<out T>(
valueParameterTypes = descriptor.extensionReceiverTypeOrEmpty() + descriptor.valueParameters.map { it.argumentValueType },
hasExtensionReceiver = descriptor.extensionReceiverParameter != null,
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
numDefaults = 0)
numDefaults = 0,
isPlatform = descriptor is MemberDescriptor && descriptor.isPlatform)
val ValueParameterDescriptor.argumentValueType: KotlinType
get() = varargElementType ?: type
@@ -219,7 +219,7 @@ class OverloadingConflictResolver<C : Any>(
}
/**
* Returns `true` if `d1` is definitely not less specific than `d2`,
* Returns `true` if [call1] is definitely not less specific than [call2],
* `false` otherwise.
*/
private fun compareCallsByUsedArguments(
@@ -237,6 +237,9 @@ class OverloadingConflictResolver<C : Any>(
if (isGeneric1 && isGeneric2) return false
}
if (!call1.isPlatform && call2.isPlatform) return true
if (call1.isPlatform && !call2.isPlatform) return false
return createEmptyConstraintSystem().isSignatureNotLessSpecific(call1, call2, SpecificityComparisonWithNumerics, specificityComparator)
}