Discriminate unsigned types in overload resolution
#KT-24717 Fixed Relates to #KT-25996 and #KT-25997
This commit is contained in:
+20
-12
@@ -280,20 +280,28 @@ open class OverloadingConflictResolver<C : Any>(
|
|||||||
val _double = builtIns.doubleType
|
val _double = builtIns.doubleType
|
||||||
val _float = builtIns.floatType
|
val _float = builtIns.floatType
|
||||||
|
|
||||||
if (UnsignedTypes.isUnsignedType(specific) && UnsignedTypes.isUnsignedType(general)) {
|
val isSpecificUnsigned = UnsignedTypes.isUnsignedType(specific)
|
||||||
val uLong = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uLong)?.defaultType ?: return false
|
val isGeneralUnsigned = UnsignedTypes.isUnsignedType(general)
|
||||||
val uInt = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uInt)?.defaultType ?: return false
|
return when {
|
||||||
val uByte = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uByte)?.defaultType ?: return false
|
isSpecificUnsigned && isGeneralUnsigned -> {
|
||||||
val uShort = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.uShort)?.defaultType ?: return false
|
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)
|
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
|
|
||||||
|
|
||||||
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -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 { _<Int>() }
|
||||||
|
foo(1u) checkType { _<String>() }
|
||||||
|
|
||||||
|
foo(2147483648) checkType { _<String>() }
|
||||||
|
foo(<!INTEGER_OVERFLOW!>2147483647 + 1<!>) checkType { _<Int>() }
|
||||||
|
|
||||||
|
fooByte(1) checkType { _<Int>() }
|
||||||
|
fooByte(1u) checkType { _<String>() }
|
||||||
|
|
||||||
|
fooShort(1) checkType { _<Int>() }
|
||||||
|
fooShort(1u) checkType { _<String>() }
|
||||||
|
|
||||||
|
fooLong(1) checkType { _<Int>() }
|
||||||
|
fooLong(1u) checkType { _<String>() }
|
||||||
|
}
|
||||||
+14
@@ -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
|
||||||
Reference in New Issue
Block a user