Make unary minus and unary plus return int for byte and short

This commit is contained in:
Natalia Ukhorskaya
2013-12-19 17:42:28 +04:00
parent 802c1b772f
commit 4329c42e3f
23 changed files with 76 additions and 68 deletions
Binary file not shown.
Binary file not shown.
+4 -4
View File
@@ -73,7 +73,7 @@ public final class Byte : jet.Number, jet.Comparable<jet.Byte> {
public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean
public open override /*1*/ fun hashCode(): jet.Int
public final fun inc(): jet.Byte
public final fun minus(): jet.Byte
public final fun minus(): jet.Int
public final fun minus(/*0*/ other: jet.Byte): jet.Int
public final fun minus(/*0*/ other: jet.Char): jet.Int
public final fun minus(/*0*/ other: jet.Double): jet.Double
@@ -88,7 +88,7 @@ public final class Byte : jet.Number, jet.Comparable<jet.Byte> {
public final fun mod(/*0*/ other: jet.Int): jet.Int
public final fun mod(/*0*/ other: jet.Long): jet.Long
public final fun mod(/*0*/ other: jet.Short): jet.Int
public final fun plus(): jet.Byte
public final fun plus(): jet.Int
public final fun plus(/*0*/ other: jet.Byte): jet.Int
public final fun plus(/*0*/ other: jet.Char): jet.Int
public final fun plus(/*0*/ other: jet.Double): jet.Double
@@ -1493,7 +1493,7 @@ public final class Short : jet.Number, jet.Comparable<jet.Short> {
public open override /*1*/ fun equals(/*0*/ other: jet.Any?): jet.Boolean
public open override /*1*/ fun hashCode(): jet.Int
public final fun inc(): jet.Short
public final fun minus(): jet.Short
public final fun minus(): jet.Int
public final fun minus(/*0*/ other: jet.Byte): jet.Int
public final fun minus(/*0*/ other: jet.Char): jet.Int
public final fun minus(/*0*/ other: jet.Double): jet.Double
@@ -1508,7 +1508,7 @@ public final class Short : jet.Number, jet.Comparable<jet.Short> {
public final fun mod(/*0*/ other: jet.Int): jet.Int
public final fun mod(/*0*/ other: jet.Long): jet.Long
public final fun mod(/*0*/ other: jet.Short): jet.Int
public final fun plus(): jet.Short
public final fun plus(): jet.Int
public final fun plus(/*0*/ other: jet.Byte): jet.Int
public final fun plus(/*0*/ other: jet.Char): jet.Int
public final fun plus(/*0*/ other: jet.Double): jet.Double
@@ -6,8 +6,8 @@ fun box(): String {
val a5: Double = 1.0.minus()
val a6: Float = 1f.minus()
if (a1 != -1.toByte()) return "fail 1"
if (a2 != -1.toShort()) return "fail -1"
if (a1 != (-1).toByte()) return "fail 1"
if (a2 != (-1).toShort()) return "fail -1"
if (a3 != -1) return "fail 3"
if (a4 != -1L) return "fail 4"
if (a5 != -1.0) return "fail 5"
@@ -6,8 +6,8 @@ fun box(): String {
val a5: Double? = 1.0.minus()
val a6: Float? = 1f.minus()
if (a1!! != -1.toByte()) return "fail 1"
if (a2!! != -1.toShort()) return "fail 2"
if (a1!! != (-1).toByte()) return "fail 1"
if (a2!! != (-1).toShort()) return "fail 2"
if (a3!! != -1) return "fail 3"
if (a4!! != -1L) return "fail 4"
if (a5!! != -1.0) return "fail 5"
@@ -1,6 +1,6 @@
fun box(): String {
if (!foo(1.toByte())) return "fail 1"
if (!foo(-1.toByte())) return "fail 2"
if (!foo((1.toByte()).inc())) return "fail 2"
return "OK"
}
@@ -6,8 +6,8 @@ fun box(): String {
val a5: Double = -1.0
val a6: Float = -1f
if (a1 != -1.toByte()) return "fail 1"
if (a2 != -1.toShort()) return "fail 2"
if (a1 != (-1).toByte()) return "fail 1"
if (a2 != (-1).toShort()) return "fail 2"
if (a3 != -1) return "fail 3"
if (a4 != -1L) return "fail 4"
if (a5 != -1.0) return "fail 5"
@@ -6,8 +6,8 @@ fun box(): String {
val a5: Double? = -1.0
val a6: Float? = -1f
if (a1!! != -1.toByte()) return "fail 1"
if (a2!! != -1.toShort()) return "fail 2"
if (a1!! != (-1).toByte()) return "fail 1"
if (a2!! != (-1).toShort()) return "fail 2"
if (a3!! != -1) return "fail 3"
if (a4!! != -1L) return "fail 4"
if (a5!! != -1.0) return "fail 5"
@@ -7,11 +7,11 @@ fun box(): String {
val ann = javaClass<MyClass>().getAnnotation(javaClass<Ann>())
if (ann == null) return "fail: cannot find Ann on MyClass}"
if (ann.i != -2) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.s != -2.toShort()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.s != (-2).toShort()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.f != -2.toFloat()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.d != -2.toDouble()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.l != -2.toLong()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.b != -2.toByte()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
if (ann.b != (-2).toByte()) return "fail: annotation parameter i should be -2, but was ${ann.i}"
return "OK"
}
@@ -1,7 +1,7 @@
data class A(val a: Byte)
fun box() : String {
val v1 = A(-10.toByte()).hashCode()
val v2 = (-10.toByte() as Byte?)!!.hashCode()
val v1 = A(10.toByte()).hashCode()
val v2 = (10.toByte() as Byte?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -1,7 +1,7 @@
data class A(val a: Short)
fun box() : String {
val v1 = A(-10.toShort()).hashCode()
val v2 = (-10.toShort() as Short?)!!.hashCode()
val v1 = A(10.toShort()).hashCode()
val v2 = (10.toShort() as Short?)!!.hashCode()
return if( v1 == v2 ) "OK" else "$v1 $v2"
}
@@ -14,23 +14,23 @@ fun box(): String {
}
val list2 = ArrayList<Byte>()
val range2 = 10.toByte()..-5.toByte()
val range2 = 10.toByte()..(-5).toByte()
for (i in range2) {
list2.add(i)
if (list2.size() > 23) break
}
if (list2 != listOf<Byte>()) {
return "Wrong elements for 10.toByte()..-5.toByte(): $list2"
return "Wrong elements for 10.toByte()..(-5).toByte(): $list2"
}
val list3 = ArrayList<Short>()
val range3 = 10.toShort()..-5.toShort()
val range3 = 10.toShort()..(-5).toShort()
for (i in range3) {
list3.add(i)
if (list3.size() > 23) break
}
if (list3 != listOf<Short>()) {
return "Wrong elements for 10.toShort()..-5.toShort(): $list3"
return "Wrong elements for 10.toShort()..(-5).toShort(): $list3"
}
val list4 = ArrayList<Long>()
@@ -13,21 +13,21 @@ fun box(): String {
}
val list2 = ArrayList<Byte>()
for (i in 10.toByte()..-5.toByte()) {
for (i in 10.toByte()..(-5).toByte()) {
list2.add(i)
if (list2.size() > 23) break
}
if (list2 != listOf<Byte>()) {
return "Wrong elements for 10.toByte()..-5.toByte(): $list2"
return "Wrong elements for 10.toByte()..(-5).toByte(): $list2"
}
val list3 = ArrayList<Short>()
for (i in 10.toShort()..-5.toShort()) {
for (i in 10.toShort()..(-5).toShort()) {
list3.add(i)
if (list3.size() > 23) break
}
if (list3 != listOf<Short>()) {
return "Wrong elements for 10.toShort()..-5.toShort(): $list3"
return "Wrong elements for 10.toShort()..(-5).toShort(): $list3"
}
val list4 = ArrayList<Long>()
@@ -7,14 +7,15 @@ fun test() {
fooInt(-1)
fooInt(<!TYPE_MISMATCH!>-1111111111111111111<!>)
fooInt(-1.toInt())
fooInt(<!TYPE_MISMATCH!>-1.toByte()<!>)
fooInt(-1.toByte())
fooInt(<!TYPE_MISMATCH!>-1.toLong()<!>)
fooInt(<!TYPE_MISMATCH!>-1.toShort()<!>)
fooInt(-1.toShort())
fooByte(-1)
fooByte(<!TYPE_MISMATCH!>-1111111111111111111<!>)
fooByte(<!TYPE_MISMATCH!>-1.toInt()<!>)
fooByte(-1.toByte())
fooByte(<!TYPE_MISMATCH!>-1.toByte()<!>)
fooByte((-1).toByte())
fooByte(<!TYPE_MISMATCH!>-1.toLong()<!>)
fooByte(<!TYPE_MISMATCH!>-1.toShort()<!>)
@@ -30,5 +31,6 @@ fun test() {
fooShort(<!TYPE_MISMATCH!>-1.toInt()<!>)
fooShort(<!TYPE_MISMATCH!>-1.toByte()<!>)
fooShort(<!TYPE_MISMATCH!>-1.toLong()<!>)
fooShort(-1.toShort())
fooShort(<!TYPE_MISMATCH!>-1.toShort()<!>)
fooShort((-1).toShort())
}
@@ -1,8 +1,8 @@
val p1 = -1
val p2 = -1.toLong()
val p3 = -1.toByte()
val p3 = (-1).toByte()
val p4 = -1.toInt()
val p5 = -1.toShort()
val p5 = (-1).toShort()
val p6 = -1111111111111111111
fun fooInt(p: Int) = p
@@ -13,8 +13,8 @@ val l2: Byte = <!TYPE_MISMATCH!>-1.toLong()<!>
val l3: Int = <!TYPE_MISMATCH!>-1.toLong()<!>
val l4: Short = <!TYPE_MISMATCH!>-1.toLong()<!>
val b1: Byte = -1.toByte()
val b2: Int = <!TYPE_MISMATCH!>-1.toByte()<!>
val b1: Byte = <!TYPE_MISMATCH!>-1.toByte()<!>
val b2: Int = -1.toByte()
val b3: Long = <!TYPE_MISMATCH!>-1.toByte()<!>
val b4: Short = <!TYPE_MISMATCH!>-1.toByte()<!>
@@ -24,6 +24,6 @@ val i3: Long = <!TYPE_MISMATCH!>-1.toInt()<!>
val i4: Short = <!TYPE_MISMATCH!>-1.toInt()<!>
val s1: Byte = <!TYPE_MISMATCH!>-1.toShort()<!>
val s2: Int = <!TYPE_MISMATCH!>-1.toShort()<!>
val s2: Int = -1.toShort()
val s3: Long = <!TYPE_MISMATCH!>-1.toShort()<!>
val s4: Short = -1.toShort()
val s4: Short = <!TYPE_MISMATCH!>-1.toShort()<!>
@@ -7,10 +7,16 @@ val p1 = -1
val p2 = -1.toLong()
// val p3: -1.toByte()
val p3 = -1.toByte()
val p3 = (-1).toByte()
// val p3a: -1.toInt()
val p3a =-1.toByte()
// val p4: -1.toInt()
val p4 = -1.toInt()
// val p5: -1.toShort()
val p5 = -1.toShort()
val p5 = (-1).toShort()
// val p5a: -1.toInt()
val p5a = -1.toShort()
@@ -25,16 +25,16 @@ val l3: Int = -1.toLong()
val l4: Short = -1.toLong()
// val b1: -1.toByte()
// val b1: -1.toInt()
val b1: Byte = -1.toByte()
// val b2: -1.toByte()
// val b2: -1.toInt()
val b2: Int = -1.toByte()
// val b3: -1.toByte()
// val b3: -1.toInt()
val b3: Long = -1.toByte()
// val b4: -1.toByte()
// val b4: -1.toInt()
val b4: Short = -1.toByte()
@@ -50,14 +50,14 @@ val i3: Long = -1.toInt()
// val i4: -1.toInt()
val i4: Short = -1.toInt()
// val s1: -1.toShort()
// val s1: -1.toInt()
val s1: Byte = -1.toShort()
// val s2: -1.toShort()
// val s2: -1.toInt()
val s2: Int = -1.toShort()
// val s3: -1.toShort()
// val s3: -1.toInt()
val s3: Long = -1.toShort()
// val s4: -1.toShort()
// val s4: -1.toInt()
val s4: Short = -1.toShort()
+4 -4
View File
@@ -387,8 +387,8 @@ public class Short private () : Number, Comparable<Short> {
public fun inc() : Short
public fun dec() : Short
public fun plus() : Short
public fun minus() : Short
public fun plus() : Int
public fun minus() : Int
public override fun toDouble() : Double
public override fun toFloat() : Float
@@ -461,8 +461,8 @@ public class Byte private () : Number, Comparable<Byte> {
public fun inc() : Byte
public fun dec() : Byte
public fun plus() : Byte
public fun minus() : Byte
public fun plus() : Int
public fun minus() : Int
public override fun toDouble() : Double
public override fun toFloat() : Float
@@ -25,13 +25,13 @@ fun box(): Boolean {
if (cn.toFloat() != -3.6.toFloat()) {
return false
}
if (cn.toByte() != -3.toByte()) {
if (cn.toByte() != (-3).toByte()) {
return false
}
if (cn.toInt() != -3) {
return false
}
if (cn.toShort() != -3.toShort()) {
if (cn.toShort() != (-3).toShort()) {
return false
}
@@ -59,13 +59,13 @@ fun box(): Boolean {
if (fn.toFloat() != -3.6.toFloat()) {
return false
}
if (fn.toByte() != -3.toByte()) {
if (fn.toByte() != (-3).toByte()) {
return false
}
if (fn.toInt() != -3) {
return false
}
if (fn.toShort() != -3.toShort()) {
if (fn.toShort() != (-3).toShort()) {
return false
}
return true
@@ -18,7 +18,7 @@ fun box(): Boolean {
return false
}
val c2: Int = -5
if (c2.toShort() != -5.toShort()) {
if (c2.toShort() != (-5).toShort()) {
return false
}
if (c2.toFloat() != -5.toFloat()) {
@@ -45,8 +45,8 @@ public class RangeIterationTest {
test fun emptyRange() {
doTest(10..5, 10, 5, 1, listOf())
doTest(10.toByte()..-5.toByte(), 10.toByte(), -5.toByte(), 1, listOf())
doTest(10.toShort()..-5.toShort(), 10.toShort(), -5.toShort(), 1, listOf())
doTest(10.toByte()..(-5).toByte(), 10.toByte(), (-5).toByte(), 1, listOf())
doTest(10.toShort()..(-5).toShort(), 10.toShort(), (-5).toShort(), 1, listOf())
doTest(10.toLong()..-5.toLong(), 10.toLong(), -5.toLong(), 1.toLong(), listOf())
doTest('z'..'a', 'z', 'a', 1, listOf())
+10 -10
View File
@@ -23,12 +23,12 @@ public class RangeTest {
}
test fun byteRange() {
val range = -5.toByte()..9.toByte()
assertFalse(-100.toByte() in range)
assertFalse(-6.toByte() in range)
val range = (-5).toByte()..9.toByte()
assertFalse((-100).toByte() in range)
assertFalse((-6).toByte() in range)
assertTrue(-5.toByte() in range)
assertTrue(-4.toByte() in range)
assertTrue((-5).toByte() in range)
assertTrue((-4).toByte() in range)
assertTrue(0.toByte() in range)
assertTrue(3.toByte() in range)
assertTrue(8.toByte() in range)
@@ -39,12 +39,12 @@ public class RangeTest {
}
test fun shortRange() {
val range = -5.toShort()..9.toShort()
assertFalse(-1000.toShort() in range)
assertFalse(-6.toShort() in range)
val range = (-5).toShort()..9.toShort()
assertFalse((-1000).toShort() in range)
assertFalse((-6).toShort() in range)
assertTrue(-5.toShort() in range)
assertTrue(-4.toShort() in range)
assertTrue((-5).toShort() in range)
assertTrue((-4).toShort() in range)
assertTrue(0.toShort() in range)
assertTrue(3.toShort() in range)
assertTrue(8.toShort() in range)