Use type from compile time value for binary expression

This commit is contained in:
Natalia Ukhorskaya
2013-12-04 18:10:37 +04:00
parent 6331dd2308
commit 53a5264aaf
42 changed files with 685 additions and 42 deletions
@@ -0,0 +1,15 @@
package test
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(val c1: Int)
Ann('a' - 'a') class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.c1 != 0) return "fail : expected = ${1}, actual = ${annotation.c1}"
return "OK"
}
@@ -0,0 +1,23 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val b: Byte,
val s: Short,
val i: Int,
val l: Long
)
Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.b != 1.toByte()) return "fail 1"
if (annotation.s != 1.toShort()) return "fail 2"
if (annotation.i != 1) return "fail 2"
if (annotation.l != 1.toLong()) return "fail 2"
return "OK"
}
// EXPECTED: Ann[b = IntegerValueType(1): IntegerValueType(1), i = IntegerValueType(1): IntegerValueType(1), l = IntegerValueType(1): IntegerValueType(1), s = IntegerValueType(1): IntegerValueType(1)]
@@ -0,0 +1,23 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Int,
val p2: Int,
val p3: Int,
val p4: Int,
val p5: Int
)
Ann(1 plus 1, 1 minus 1, 1 times 1, 1 div 1, 1 mod 1) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != 2) return "fail 1"
if (annotation.p2 != 0) return "fail 2"
if (annotation.p3 != 1) return "fail 3"
if (annotation.p4 != 1) return "fail 4"
if (annotation.p5 != 0) return "fail 5"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Int,
val p2: Short,
val p3: Byte,
val p4: Int,
val p5: Int,
val p6: Int
)
val prop1: Int = 1 or 1
val prop2: Short = 1 and 1
val prop3: Byte = 1 xor 1
val prop4: Int = 1 shl 1
val prop5: Int = 1 shr 1
val prop6: Int = 1 ushr 1
Ann(1 or 1, 1 and 1, 1 xor 1, 1 shl 1, 1 shr 1, 1 ushr 1) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Int,
val p2: Int,
val p3: Int,
val p4: Int,
val p5: Long,
val p6: Long
)
Ann(
p1 = java.lang.Byte.MAX_VALUE + 1,
p2 = java.lang.Short.MAX_VALUE + 1,
p3 = java.lang.Integer.MAX_VALUE + 1,
p4 = java.lang.Integer.MAX_VALUE + 1,
p5 = java.lang.Integer.MAX_VALUE + 1.toLong(),
p6 = java.lang.Long.MAX_VALUE + 1
) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != 128) return "fail 1, expected = ${128}, actual = ${annotation.p1}"
if (annotation.p2 != 32768) return "fail 2, expected = ${32768}, actual = ${annotation.p2}"
if (annotation.p3 != -2147483648) return "fail 3, expected = ${-2147483648}, actual = ${annotation.p3}"
if (annotation.p4 != -2147483648) return "fail 4, expected = ${-2147483648}, actual = ${annotation.p4}"
if (annotation.p5 != 2147483648.toLong()) return "fail 5, expected = ${2147483648}, actual = ${annotation.p5}"
if (annotation.p6 != java.lang.Long.MAX_VALUE + 1) return "fail 5, expected = ${java.lang.Long.MAX_VALUE + 1}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,29 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Int,
val p2: Byte,
val p3: Byte,
val p4: Int,
val p5: Int
)
Ann(
p1 = java.lang.Byte.MAX_VALUE + 1,
p2 = 1 + 1,
p3 = java.lang.Byte.MAX_VALUE - 1,
p4 = 1 + 1,
p5 = 1.toByte() + 1
) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != 128) return "fail 1, expected = ${128}, actual = ${annotation.p1}"
if (annotation.p2 != 2.toByte()) return "fail 2, expected = ${2}, actual = ${annotation.p2}"
if (annotation.p3 != 126.toByte()) return "fail 3, expected = ${126}, actual = ${annotation.p3}"
if (annotation.p4 != 2) return "fail 4, expected = ${2}, actual = ${annotation.p4}"
if (annotation.p5 != 2) return "fail 5, expected = ${2}, actual = ${annotation.p5}"
return "OK"
}
@@ -0,0 +1,29 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Int,
val p2: Int,
val p3: Long,
val p4: Long,
val p5: Int
)
Ann(
p1 = java.lang.Integer.MAX_VALUE + 1,
p2 = 1 + 1,
p3 = java.lang.Integer.MAX_VALUE + 1,
p4 = 1 + 1,
p5 = 1.toInt() + 1.toInt()
) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != -2147483648) return "fail 1, expected = ${-2147483648}, actual = ${annotation.p1}"
if (annotation.p2 != 2) return "fail 2, expected = ${2}, actual = ${annotation.p2}"
if (annotation.p3 != -2147483648.toLong()) return "fail 3, expected = ${-2147483648}, actual = ${annotation.p3}"
if (annotation.p4 != 2.toLong()) return "fail 4, expected = ${2}, actual = ${annotation.p4}"
if (annotation.p5 != 2) return "fail 5, expected = ${2}, actual = ${annotation.p5}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val prop1: Byte = 1 * 1
val prop2: Short = 1 * 1
val prop3: Int = 1 * 1
val prop4: Long = 1 * 1
val prop5: Double = 1.0 * 1.0
val prop6: Float = 1.0.toFloat() * 1.0.toFloat()
Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1, 1.0 * 1.0, 1.0.toFloat() * 1.0.toFloat()) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val prop1: Byte = 1 - 1
val prop2: Short = 1 - 1
val prop3: Int = 1 - 1
val prop4: Long = 1 - 1
val prop5: Double = 1.0 - 1.0
val prop6: Float = 1.0.toFloat() - 1.0.toFloat()
Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1, 1.0 - 1.0, 1.0.toFloat() - 1.0.toFloat()) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val prop1: Byte = 1 % 1
val prop2: Short = 1 % 1
val prop3: Int = 1 % 1
val prop4: Long = 1 % 1
val prop5: Double = 1.0 % 1.0
val prop6: Float = 1.0.toFloat() % 1.0.toFloat()
Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1, 1.0 % 1.0, 1.0.toFloat() % 1.0.toFloat()) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val prop1: Byte = (1 + 2) * 2
val prop2: Short = (1 + 2) * 2
val prop3: Int = (1 + 2) * 2
val prop4: Long = (1 + 2) * 2
val prop5: Double = (1.0 + 2) * 2
val prop6: Float = (1.toFloat() + 2) * 2
Ann((1 + 2) * 2, (1 + 2) * 2, (1 + 2) * 2, (1 + 2) * 2, (1.0 + 2) * 2, (1.toFloat() + 2) * 2) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val prop1: Byte = 1 + 1
val prop2: Short = 1 + 1
val prop3: Int = 1 + 1
val prop4: Long = 1 + 1
val prop5: Double = 1.0 + 1.0
val prop6: Float = 1.0.toFloat() + 1.0.toFloat()
Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1, 1.0 + 1.0, 1.0.toFloat() + 1.0.toFloat()) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,29 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Int,
val p2: Int,
val p3: Int,
val p4: Int,
val p5: Int
)
val prop1: Int = 1.plus(1)
val prop2: Int = 1.minus(1)
val prop3: Int = 1.times(1)
val prop4: Int = 1.div(1)
val prop5: Int = 1.mod(1)
Ann(prop1, prop2, prop3, prop4, prop5) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
return "OK"
}
@@ -3,30 +3,30 @@ import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val b1: Byte,
val b2: Short,
val b3: Int,
val b4: Long,
val b5: Double,
val b6: Float
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val b1: Byte = -1
val b2: Short = -1
val b3: Int = -1
val b4: Long = -1
val b5: Double = -1.0
val b6: Float = -1.0.toFloat()
val prop1: Byte = -1
val prop2: Short = -1
val prop3: Int = -1
val prop4: Long = -1
val prop5: Double = -1.0
val prop6: Float = -1.0.toFloat()
Ann(b1, b2, b3, b4, b5, b6) class MyClass
Ann(prop1, prop2, prop3, prop4, prop5, prop6) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.b1 != b1) return "fail 1"
if (annotation.b2 != b2) return "fail 2"
if (annotation.b3 != b3) return "fail 3"
if (annotation.b4 != b4) return "fail 4"
if (annotation.b5 != b5) return "fail 5"
if (annotation.b6 != b6) return "fail 6"
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}
@@ -0,0 +1,32 @@
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
Retention(RetentionPolicy.RUNTIME)
annotation class Ann(
val p1: Byte,
val p2: Short,
val p3: Int,
val p4: Long,
val p5: Double,
val p6: Float
)
val prop1: Byte = +1
val prop2: Short = +1
val prop3: Int = +1
val prop4: Long = +1
val prop5: Double = +1.0
val prop6: Float = +1.0.toFloat()
Ann(prop1, prop2, prop3, prop4, prop5, prop6) class MyClass
fun box(): String {
val annotation = javaClass<MyClass>().getAnnotation(javaClass<Ann>())!!
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
return "OK"
}