diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt index 889ea6a4289..0b8d623e745 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt @@ -280,20 +280,28 @@ open class OverloadingConflictResolver( val _double = builtIns.doubleType val _float = builtIns.floatType - if (UnsignedTypes.isUnsignedType(specific) && UnsignedTypes.isUnsignedType(general)) { - val uLong = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uLong)?.defaultType ?: return false - val uInt = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uInt)?.defaultType ?: return false - val uByte = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uByte)?.defaultType ?: return false - val uShort = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uShort)?.defaultType ?: return false + val isSpecificUnsigned = UnsignedTypes.isUnsignedType(specific) + val isGeneralUnsigned = UnsignedTypes.isUnsignedType(general) + return when { + isSpecificUnsigned && isGeneralUnsigned -> { + val uLong = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uLong)?.defaultType ?: return false + val uInt = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uInt)?.defaultType ?: return false + val uByte = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uByte)?.defaultType ?: return false + val uShort = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uShort)?.defaultType ?: return false - return isNonSubtypeNotLessSpecific(specific, general, _double, _float, uLong, uInt, uByte, uShort) - } else { - val _long = builtIns.longType - val _int = builtIns.intType - val _byte = builtIns.byteType - val _short = builtIns.shortType + isNonSubtypeNotLessSpecific(specific, general, _double, _float, uLong, uInt, uByte, uShort) + } - return isNonSubtypeNotLessSpecific(specific, general, _double, _float, _long, _int, _byte, _short) + !isSpecificUnsigned && isGeneralUnsigned -> true + + else -> { + val _long = builtIns.longType + val _int = builtIns.intType + val _byte = builtIns.byteType + val _short = builtIns.shortType + + isNonSubtypeNotLessSpecific(specific, general, _double, _float, _long, _int, _byte, _short) + } } } diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.kt b/compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.kt new file mode 100644 index 00000000000..6a0b8b5136a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.kt @@ -0,0 +1,39 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !CHECK_TYPE + +fun foo(x: Int): Int = 0 + +@JvmName("fooUInt") +fun foo(x: UInt): String = "" +fun foo(x: UByte): String = "" +fun foo(x: UShort): String = "" +fun foo(x: ULong): String = "" + +fun fooByte(x: Byte): Int = 0 +@JvmName("fooUByte") +fun fooByte(x: UByte): String = "" + +fun fooShort(x: Short): Int = 0 +@JvmName("fooUByte") +fun fooShort(x: UShort): String = "" + +fun fooLong(x: Long): Int = 0 +@JvmName("fooULong") +fun fooLong(x: ULong): String = "" + +fun test() { + foo(1) checkType { _() } + foo(1u) checkType { _() } + + foo(2147483648) checkType { _() } + foo(2147483647 + 1) checkType { _() } + + fooByte(1) checkType { _() } + fooByte(1u) checkType { _() } + + fooShort(1) checkType { _() } + fooShort(1u) checkType { _() } + + fooLong(1) checkType { _() } + fooLong(1u) checkType { _() } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.txt b/compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.txt new file mode 100644 index 00000000000..bafe60f62f3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.txt @@ -0,0 +1,14 @@ +package + +public fun foo(/*0*/ x: kotlin.Int): kotlin.Int +public fun foo(/*0*/ x: kotlin.UByte): kotlin.String +@kotlin.jvm.JvmName(name = "fooUInt") public fun foo(/*0*/ x: kotlin.UInt): kotlin.String +public fun foo(/*0*/ x: kotlin.ULong): kotlin.String +public fun foo(/*0*/ x: kotlin.UShort): kotlin.String +public fun fooByte(/*0*/ x: kotlin.Byte): kotlin.Int +@kotlin.jvm.JvmName(name = "fooUByte") public fun fooByte(/*0*/ x: kotlin.UByte): kotlin.String +public fun fooLong(/*0*/ x: kotlin.Long): kotlin.Int +@kotlin.jvm.JvmName(name = "fooULong") public fun fooLong(/*0*/ x: kotlin.ULong): kotlin.String +public fun fooShort(/*0*/ x: kotlin.Short): kotlin.Int +@kotlin.jvm.JvmName(name = "fooUByte") public fun fooShort(/*0*/ x: kotlin.UShort): kotlin.String +public fun test(): kotlin.Unit