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
@@ -99,7 +99,12 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
override fun visitParenthesizedExpression(expression: JetParenthesizedExpression, expectedType: JetType?): CompileTimeConstant<*>? {
val deparenthesizedExpression = JetPsiUtil.deparenthesize(expression)
if (deparenthesizedExpression != null && deparenthesizedExpression != expression) {
return evaluate(deparenthesizedExpression, expectedType)
val compileTimeConstant = evaluate(deparenthesizedExpression, expectedType)
val isDeparentesizedPure = trace.get(BindingContext.IS_PURE_CONSTANT_EXPRESSION, deparenthesizedExpression)
if (isDeparentesizedPure != null && isDeparentesizedPure!!) {
trace.record(BindingContext.IS_PURE_CONSTANT_EXPRESSION, expression, true)
}
return compileTimeConstant
}
return null
}
@@ -359,7 +359,7 @@ public class CandidateResolver {
return;
}
if (storedContextForArgument == null) {
JetType type = argumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression);
JetType type = ArgumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression);
checkResultArgumentType(type, argument, context);
return;
}
@@ -372,7 +372,13 @@ public class CandidateResolver {
}
else {
completeNestedCallsInference(contextForArgument);
type = contextForArgument.candidateCall.getResultingDescriptor().getReturnType();
JetType recordedType = context.trace.get(BindingContext.EXPRESSION_TYPE, expression);
if (recordedType != null && !recordedType.getConstructor().isDenotable()) {
type = ArgumentTypeResolver.updateResultArgumentTypeIfNotDenotable(context, expression);
}
else {
type = contextForArgument.candidateCall.getResultingDescriptor().getReturnType();
}
checkValueArgumentTypes(contextForArgument);
}
JetType result = BindingContextUtils.updateRecordedType(
@@ -855,6 +855,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(UNSUPPORTED.on(operationSign, "Unknown operation"));
result = JetTypeInfo.create(null, context.dataFlowInfo);
}
CompileTimeConstant<?> value = ConstantExpressionEvaluator.object$.
evaluate(expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType);
if (value != null) {
return createCompileTimeConstantTypeInfo(value, expression, contextWithExpectedType);
}
return DataFlowUtils.checkType(result, expression, contextWithExpectedType);
}
@@ -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"
}
@@ -0,0 +1,30 @@
fun fooInt(p: Int) = p
fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p
fun fooShort(p: Short) = p
fun test() {
fooInt(1 - 1)
fooInt(1 - 1.toInt())
fooInt(1 - 1.toByte())
fooInt(<!TYPE_MISMATCH!>1 - 1.toLong()<!>)
fooInt(1 - 1.toShort())
fooByte(1 - 1)
fooByte(<!TYPE_MISMATCH!>1 - 1.toInt()<!>)
fooByte(<!TYPE_MISMATCH!>1 - 1.toByte()<!>)
fooByte(<!TYPE_MISMATCH!>1 - 1.toLong()<!>)
fooByte(<!TYPE_MISMATCH!>1 - 1.toShort()<!>)
fooLong(1 - 1)
fooLong(<!TYPE_MISMATCH!>1 - 1.toInt()<!>)
fooLong(<!TYPE_MISMATCH!>1 - 1.toByte()<!>)
fooLong(1 - 1.toLong())
fooLong(<!TYPE_MISMATCH!>1 - 1.toShort()<!>)
fooShort(1 - 1)
fooShort(<!TYPE_MISMATCH!>1 - 1.toInt()<!>)
fooShort(<!TYPE_MISMATCH!>1 - 1.toByte()<!>)
fooShort(<!TYPE_MISMATCH!>1 - 1.toLong()<!>)
fooShort(<!TYPE_MISMATCH!>1 - 1.toShort()<!>)
}
@@ -0,0 +1,36 @@
val p1 = 1 - 1
val p2 = 1 - 1.toLong()
val p3 = 1 - 1.toByte()
val p4 = 1 - 1.toInt()
val p5 = 1 - 1.toShort()
fun fooInt(p: Int) = p
fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p
fun fooShort(p: Short) = p
fun test() {
fooInt(p1)
fooInt(<!TYPE_MISMATCH!>p2<!>)
fooInt(p3)
fooInt(p4)
fooInt(p5)
fooLong(<!TYPE_MISMATCH!>p1<!>)
fooLong(p2)
fooLong(<!TYPE_MISMATCH!>p3<!>)
fooLong(<!TYPE_MISMATCH!>p4<!>)
fooLong(<!TYPE_MISMATCH!>p5<!>)
fooShort(<!TYPE_MISMATCH!>p1<!>)
fooShort(<!TYPE_MISMATCH!>p2<!>)
fooShort(<!TYPE_MISMATCH!>p3<!>)
fooShort(<!TYPE_MISMATCH!>p4<!>)
fooShort(<!TYPE_MISMATCH!>p5<!>)
fooByte(<!TYPE_MISMATCH!>p1<!>)
fooByte(<!TYPE_MISMATCH!>p2<!>)
fooByte(<!TYPE_MISMATCH!>p3<!>)
fooByte(<!TYPE_MISMATCH!>p4<!>)
fooByte(<!TYPE_MISMATCH!>p5<!>)
}
@@ -0,0 +1,24 @@
val p1: Int = 1 - 1
val p2: Long = 1 - 1
val p3: Byte = 1 - 1
val p4: Short = 1 - 1
val l1: Long = 1 - 1.toLong()
val l2: Byte = <!TYPE_MISMATCH!>1 - 1.toLong()<!>
val l3: Int = <!TYPE_MISMATCH!>1 - 1.toLong()<!>
val l4: Short = <!TYPE_MISMATCH!>1 - 1.toLong()<!>
val b1: Byte = <!TYPE_MISMATCH!>1 - 1.toByte()<!>
val b2: Int = 1 - 1.toByte()
val b3: Long = <!TYPE_MISMATCH!>1 - 1.toByte()<!>
val b4: Short = <!TYPE_MISMATCH!>1 - 1.toByte()<!>
val i1: Byte = <!TYPE_MISMATCH!>1 - 1.toInt()<!>
val i2: Int = 1 - 1.toInt()
val i3: Long = <!TYPE_MISMATCH!>1 - 1.toInt()<!>
val i4: Short = <!TYPE_MISMATCH!>1 - 1.toInt()<!>
val s1: Byte = <!TYPE_MISMATCH!>1 - 1.toShort()<!>
val s2: Int = 1 - 1.toShort()
val s3: Long = <!TYPE_MISMATCH!>1 - 1.toShort()<!>
val s4: Short = <!TYPE_MISMATCH!>1 - 1.toShort()<!>
@@ -0,0 +1,26 @@
fun fooInt(p: Int) = p
fun fooLong(p: Long) = p
fun fooByte(p: Byte) = p
fun fooShort(p: Short) = p
fun test() {
fooInt(1 + 1)
fooByte(1 + 1)
fooLong(1 + 1)
fooShort(1 + 1)
fooInt(1 * 1)
fooByte(1 * 1)
fooLong(1 * 1)
fooShort(1 * 1)
fooInt(1 / 1)
fooByte(1 / 1)
fooLong(1 / 1)
fooShort(1 / 1)
fooInt(1 % 1)
fooByte(1 % 1)
fooLong(1 % 1)
fooShort(1 % 1)
}
@@ -0,0 +1,12 @@
val p1: Byte = (1 + 2) * 2
val p2: Short = (1 + 2) * 2
val p3: Int = (1 + 2) * 2
val p4: Long = (1 + 2) * 2
val b1: Byte = <!TYPE_MISMATCH!>(1.toByte() + 2) * 2<!>
val b2: Short = <!TYPE_MISMATCH!>(1.toShort() + 2) * 2<!>
val b3: Int = (1.toInt() + 2) * 2
val b4: Long = (1.toLong() + 2) * 2
val i1: Int = (1.toByte() + 2) * 2
val i2: Int = (1.toShort() + 2) * 2
@@ -9,10 +9,10 @@ annotation class BooleanAnno(val value: Boolean)
annotation class FloatAnno(val value: Float)
annotation class DoubleAnno(val value: Double)
IntAnno(42)
ShortAnno(42)
ByteAnno(42)
LongAnno(42)
IntAnno(42.toInt())
ShortAnno(42.toShort())
ByteAnno(42.toByte())
LongAnno(42.toLong())
CharAnno('A')
BooleanAnno(false)
FloatAnno(3.14.toFloat())
@@ -18,7 +18,7 @@ internal final annotation class CharAnno : jet.Annotation {
internal final fun <get-value>(): jet.Char
}
test.IntAnno(value = IntegerValueType(42): IntegerValueType(42)) test.ShortAnno(value = IntegerValueType(42): IntegerValueType(42)) test.ByteAnno(value = IntegerValueType(42): IntegerValueType(42)) test.LongAnno(value = IntegerValueType(42): IntegerValueType(42)) test.CharAnno(value = #65(A): jet.Char) test.BooleanAnno(value = false: jet.Boolean) test.FloatAnno(value = 3.14.toFloat(): jet.Float) test.DoubleAnno(value = 3.14.toDouble(): jet.Double) internal final class Class {
test.IntAnno(value = 42.toInt(): jet.Int) test.ShortAnno(value = 42.toShort(): jet.Short) test.ByteAnno(value = 42.toByte(): jet.Byte) test.LongAnno(value = 42.toLong(): jet.Long) test.CharAnno(value = #65(A): jet.Char) test.BooleanAnno(value = false: jet.Boolean) test.FloatAnno(value = 3.14.toFloat(): jet.Float) test.DoubleAnno(value = 3.14.toDouble(): jet.Double) internal final class Class {
/*primary*/ public constructor Class()
}
@@ -2,4 +2,4 @@ package test
annotation class Anno(val int: Int, val string: String, val double: Double)
Anno(42, "OK", 3.14) class Class
Anno(42.toInt(), "OK", 3.14.toDouble()) class Class
@@ -10,6 +10,6 @@ internal final annotation class Anno : jet.Annotation {
internal final fun <get-string>(): jet.String
}
test.Anno(double = 3.14.toDouble(): jet.Double, int = IntegerValueType(42): IntegerValueType(42), string = "OK": jet.String) internal final class Class {
test.Anno(double = 3.14.toDouble(): jet.Double, int = 42.toInt(): jet.Int, string = "OK": jet.String) internal final class Class {
/*primary*/ public constructor Class()
}
@@ -4,4 +4,4 @@ annotation class Ann(val c1: Char)
Ann('a' - 'a') class MyClass
// EXPECTED: Ann[c1 = 0.toInt(): jet.Int]
// EXPECTED: Ann[c1 = IntegerValueType(0): IntegerValueType(0)]
@@ -9,4 +9,4 @@ annotation class Ann(
Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass
// EXPECTED: Ann[b = 1.toByte(): jet.Byte, i = 1.toInt(): jet.Int, l = 1.toLong(): jet.Long, s = 1.toShort(): jet.Short]
// EXPECTED: Ann[b = IntegerValueType(1): IntegerValueType(1), i = IntegerValueType(1): IntegerValueType(1), l = IntegerValueType(1): IntegerValueType(1), s = IntegerValueType(1): IntegerValueType(1)]
@@ -10,4 +10,4 @@ annotation class Ann(
Ann(1 plus 1, 1 minus 1, 1 times 1, 1 div 1, 1 mod 1) class MyClass
// EXPECTED: Ann[p1 = 2.toInt(): jet.Int, p2 = 0.toInt(): jet.Int, p3 = 1.toInt(): jet.Int, p4 = 1.toInt(): jet.Int, p5 = 0.toInt(): jet.Int]
// EXPECTED: Ann[p1 = IntegerValueType(2): IntegerValueType(2), p2 = IntegerValueType(0): IntegerValueType(0), p3 = IntegerValueType(1): IntegerValueType(1), p4 = IntegerValueType(1): IntegerValueType(1), p5 = IntegerValueType(0): IntegerValueType(0)]
@@ -10,4 +10,4 @@ annotation class Ann(p1: Int,
Ann(1 or 1, 1 and 1, 1 xor 1, 1 shl 1, 1 shr 1, 1 ushr 1) class MyClass
// EXPECTED: Ann[p1 = 1.toInt(): jet.Int, p2 = 1.toShort(): jet.Short, p3 = 0.toByte(): jet.Byte, p4 = 2.toInt(): jet.Int, p5 = 0.toInt(): jet.Int, p6 = 0.toInt(): jet.Int]
// EXPECTED: Ann[p1 = IntegerValueType(1): IntegerValueType(1), p2 = IntegerValueType(1): IntegerValueType(1), p3 = IntegerValueType(0): IntegerValueType(0), p4 = IntegerValueType(2): IntegerValueType(2), p5 = IntegerValueType(0): IntegerValueType(0), p6 = IntegerValueType(0): IntegerValueType(0)]
@@ -8,4 +8,4 @@ annotation class Ann(
Ann(1 + 1, java.lang.Long.MAX_VALUE + 1 - 1, java.lang.Long.MAX_VALUE - 1) class MyClass
// EXPECTED: Ann[l1 = 2.toLong(): jet.Long, l2 = 9223372036854775807.toLong(): jet.Long, l3 = 9223372036854775806.toLong(): jet.Long]
// EXPECTED: Ann[l1 = IntegerValueType(2): IntegerValueType(2), l2 = IntegerValueType(9223372036854775807): IntegerValueType(9223372036854775807), l3 = IntegerValueType(9223372036854775806): IntegerValueType(9223372036854775806)]
@@ -18,4 +18,4 @@ Ann(
p6 = java.lang.Long.MAX_VALUE + 1
) class MyClass
// EXPECTED: Ann[p1 = 128.toInt(): jet.Int, p2 = 32768.toInt(): jet.Int, p3 = -2147483648.toInt(): jet.Int, p4 = -2147483648.toInt(): jet.Int, p5 = 2147483648.toLong(): jet.Long, p6 = -9223372036854775808.toLong(): jet.Long]
// EXPECTED: Ann[p1 = IntegerValueType(128): IntegerValueType(128), p2 = IntegerValueType(32768): IntegerValueType(32768), p3 = IntegerValueType(-2147483648): IntegerValueType(-2147483648), p4 = IntegerValueType(-2147483648): IntegerValueType(-2147483648), p5 = 2147483648.toLong(): jet.Long, p6 = IntegerValueType(-9223372036854775808): IntegerValueType(-9223372036854775808)]
@@ -16,4 +16,4 @@ Ann(
p5 = 1.toByte() + 1.toByte()
) class MyClass
// EXPECTED: Ann[p1 = 128.toInt(): jet.Int, p2 = 2.toByte(): jet.Byte, p3 = 128.toInt(): jet.Int, p4 = 2.toInt(): jet.Int, p5 = 2.toInt(): jet.Int]
// EXPECTED: Ann[p1 = IntegerValueType(128): IntegerValueType(128), p2 = IntegerValueType(2): IntegerValueType(2), p3 = IntegerValueType(128): IntegerValueType(128), p4 = 2.toInt(): jet.Int, p5 = 2.toInt(): jet.Int]
@@ -16,4 +16,4 @@ Ann(
p5 = 1.toInt() + 1.toInt()
) class MyClass
// EXPECTED: Ann[p1 = -2147483648.toInt(): jet.Int, p2 = 2.toInt(): jet.Int, p3 = -2147483648.toLong(): jet.Long, p4 = 2.toInt(): jet.Int, p5 = 2.toInt(): jet.Int]
// EXPECTED: Ann[p1 = IntegerValueType(-2147483648): IntegerValueType(-2147483648), p2 = IntegerValueType(2): IntegerValueType(2), p3 = IntegerValueType(-2147483648): IntegerValueType(-2147483648), p4 = 2.toInt(): jet.Int, p5 = 2.toInt(): jet.Int]
@@ -9,4 +9,4 @@ annotation class Ann(
Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1) class MyClass
// EXPECTED: Ann[b = 1.toByte(): jet.Byte, i = 1.toInt(): jet.Int, l = 1.toLong(): jet.Long, s = 1.toShort(): jet.Short]
// EXPECTED: Ann[b = IntegerValueType(1): IntegerValueType(1), i = IntegerValueType(1): IntegerValueType(1), l = IntegerValueType(1): IntegerValueType(1), s = IntegerValueType(1): IntegerValueType(1)]
@@ -9,4 +9,4 @@ annotation class Ann(
Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1) class MyClass
// EXPECTED: Ann[b = 0.toByte(): jet.Byte, i = 0.toInt(): jet.Int, l = 0.toLong(): jet.Long, s = 0.toShort(): jet.Short]
// EXPECTED: Ann[b = IntegerValueType(0): IntegerValueType(0), i = IntegerValueType(0): IntegerValueType(0), l = IntegerValueType(0): IntegerValueType(0), s = IntegerValueType(0): IntegerValueType(0)]
@@ -9,4 +9,4 @@ annotation class Ann(
Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1) class MyClass
// EXPECTED: Ann[b = 0.toByte(): jet.Byte, i = 0.toInt(): jet.Int, l = 0.toLong(): jet.Long, s = 0.toShort(): jet.Short]
// EXPECTED: Ann[b = IntegerValueType(0): IntegerValueType(0), i = IntegerValueType(0): IntegerValueType(0), l = IntegerValueType(0): IntegerValueType(0), s = IntegerValueType(0): IntegerValueType(0)]
@@ -4,4 +4,4 @@ annotation class Ann(i: Int)
Ann((1 + 2) * 2) class MyClass
// EXPECTED: Ann[i = 6.toInt(): jet.Int]
// EXPECTED: Ann[i = IntegerValueType(6): IntegerValueType(6)]
@@ -9,4 +9,4 @@ annotation class Ann(
Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1) class MyClass
// EXPECTED: Ann[b = 2.toByte(): jet.Byte, i = 2.toInt(): jet.Int, l = 2.toLong(): jet.Long, s = 2.toShort(): jet.Short]
// EXPECTED: Ann[b = IntegerValueType(2): IntegerValueType(2), i = IntegerValueType(2): IntegerValueType(2), l = IntegerValueType(2): IntegerValueType(2), s = IntegerValueType(2): IntegerValueType(2)]
@@ -2734,6 +2734,21 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/evaluate"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("binaryMinusDepOnExpType.kt")
public void testBinaryMinusDepOnExpType() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.kt");
}
@TestMetadata("binaryMinusIndepWoExpType.kt")
public void testBinaryMinusIndepWoExpType() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/binaryMinusIndepWoExpType.kt");
}
@TestMetadata("binaryMinusIndependentExpType.kt")
public void testBinaryMinusIndependentExpType() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt");
}
@TestMetadata("intOverflow.kt")
public void testIntOverflow() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/intOverflow.kt");
@@ -2744,11 +2759,21 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/evaluate/longOverflow.kt");
}
@TestMetadata("numberBinaryOperations.kt")
public void testNumberBinaryOperations() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.kt");
}
@TestMetadata("otherOverflow.kt")
public void testOtherOverflow() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/otherOverflow.kt");
}
@TestMetadata("parentesized.kt")
public void testParentesized() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/parentesized.kt");
}
@TestMetadata("unaryMinusDepOnExpType.kt")
public void testUnaryMinusDepOnExpType() throws Exception {
doTest("compiler/testData/diagnostics/tests/evaluate/unaryMinusDepOnExpType.kt");
@@ -397,11 +397,81 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/boxWithStdlib/evaluate"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("char.kt")
public void testChar() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/char.kt");
}
@TestMetadata("divide.kt")
public void testDivide() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/divide.kt");
}
@TestMetadata("infixCallBinary.kt")
public void testInfixCallBinary() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/infixCallBinary.kt");
}
@TestMetadata("intrincics.kt")
public void testIntrincics() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/intrincics.kt");
}
@TestMetadata("maxValue.kt")
public void testMaxValue() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/maxValue.kt");
}
@TestMetadata("maxValueByte.kt")
public void testMaxValueByte() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/maxValueByte.kt");
}
@TestMetadata("maxValueInt.kt")
public void testMaxValueInt() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/maxValueInt.kt");
}
@TestMetadata("miltiply.kt")
public void testMiltiply() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/miltiply.kt");
}
@TestMetadata("minus.kt")
public void testMinus() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/minus.kt");
}
@TestMetadata("mod.kt")
public void testMod() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/mod.kt");
}
@TestMetadata("paranthesized.kt")
public void testParanthesized() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/paranthesized.kt");
}
@TestMetadata("plus.kt")
public void testPlus() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/plus.kt");
}
@TestMetadata("simpleCallBinary.kt")
public void testSimpleCallBinary() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/simpleCallBinary.kt");
}
@TestMetadata("unaryMinus.kt")
public void testUnaryMinus() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/unaryMinus.kt");
}
@TestMetadata("unaryPlus.kt")
public void testUnaryPlus() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/evaluate/unaryPlus.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/fullJdk")