Skip to content

Commit a3cfd39

Browse files
committed
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
1 parent 926b81f commit a3cfd39

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignatureForResolvedCall.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.jetbrains.kotlin.resolve.calls.results
1818

1919
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
20+
import org.jetbrains.kotlin.descriptors.MemberDescriptor
2021
import org.jetbrains.kotlin.psi.ValueArgument
2122
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
2223
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl
@@ -55,7 +56,8 @@ fun <RC : ResolvedCall<*>> RC.createFlatSignature(): FlatSignature<RC> {
5556
call.valueArguments.map { valueArgumentToParameterType[it] },
5657
hasExtensionReceiver = originalDescriptor.extensionReceiverParameter != null,
5758
hasVarargs = originalDescriptor.valueParameters.any { it.varargElementType != null },
58-
numDefaults = numDefaults)
59+
numDefaults = numDefaults,
60+
isPlatform = originalDescriptor is MemberDescriptor && originalDescriptor.isPlatform)
5961
}
6062

6163
fun createOverloadingConflictResolver(

compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/FlatSignature.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.jetbrains.kotlin.resolve.calls.results
1818

1919
import org.jetbrains.kotlin.descriptors.CallableDescriptor
20+
import org.jetbrains.kotlin.descriptors.MemberDescriptor
2021
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
2122
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
2223
import org.jetbrains.kotlin.types.*
@@ -41,7 +42,8 @@ class FlatSignature<out T>(
4142
val valueParameterTypes: List<KotlinType?>,
4243
val hasExtensionReceiver: Boolean,
4344
val hasVarargs: Boolean,
44-
val numDefaults: Int
45+
val numDefaults: Int,
46+
val isPlatform: Boolean
4547
) {
4648
val isGeneric = typeParameters.isNotEmpty()
4749

@@ -52,7 +54,8 @@ class FlatSignature<out T>(
5254
valueParameterTypes = descriptor.extensionReceiverTypeOrEmpty() + descriptor.valueParameters.map { it.argumentValueType },
5355
hasExtensionReceiver = descriptor.extensionReceiverParameter != null,
5456
hasVarargs = descriptor.valueParameters.any { it.varargElementType != null },
55-
numDefaults = 0)
57+
numDefaults = 0,
58+
isPlatform = descriptor is MemberDescriptor && descriptor.isPlatform)
5659

5760
val ValueParameterDescriptor.argumentValueType: KotlinType
5861
get() = varargElementType ?: type

compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class OverloadingConflictResolver<C : Any>(
219219
}
220220

221221
/**
222-
* Returns `true` if `d1` is definitely not less specific than `d2`,
222+
* Returns `true` if [call1] is definitely not less specific than [call2],
223223
* `false` otherwise.
224224
*/
225225
private fun compareCallsByUsedArguments(
@@ -237,6 +237,9 @@ class OverloadingConflictResolver<C : Any>(
237237
if (isGeneric1 && isGeneric2) return false
238238
}
239239

240+
if (!call1.isPlatform && call2.isPlatform) return true
241+
if (call1.isPlatform && !call2.isPlatform) return false
242+
240243
return createEmptyConstraintSystem().isSignatureNotLessSpecific(call1, call2, SpecificityComparisonWithNumerics, specificityComparator)
241244
}
242245

0 commit comments

Comments
 (0)