Change signed to unsigned widening conversions to sign-extending

e.g. `Byte.toUInt()` now returns `UInt.MAX_VALUE` for Byte value of -1 instead of 0xFFu.

#KT-26594 Fixed
This commit is contained in:
Ilya Gorbunov
2018-09-05 06:26:12 +03:00
parent 4344005fb5
commit 82d35cfa26
5 changed files with 17 additions and 14 deletions
+5 -2
View File
@@ -199,7 +199,11 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
for (otherType in UnsignedType.values()) {
val name = otherType.capitalized
out.print(" public fun to$name(): $name = ")
out.println(if (type == otherType) "this" else "data.to${otherType.capitalized}()")
out.println(when {
otherType > type -> "data.to${otherType.capitalized}() and ${type.mask}u"
otherType == type -> "this"
else -> "data.to${otherType.capitalized}()"
})
}
out.println()
}
@@ -212,7 +216,6 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
out.println("@ExperimentalUnsignedTypes")
out.print("public fun $otherSigned.to$className(): $className = ")
out.println(when {
otherType < type -> "$className(this.to$thisSigned() and ${otherType.mask})"
otherType == type -> "$className(this)"
else -> "$className(this.to$thisSigned())"
})