[FIR] Support constant unary operators for integer literal operators

^KT-38895
This commit is contained in:
Dmitriy Novozhilov
2022-02-04 11:06:27 +03:00
committed by teamcity
parent 52b72a7dac
commit 1591518cf6
14 changed files with 116 additions and 20 deletions
@@ -0,0 +1,31 @@
FILE: constantUnaryOperators.kt
public final val i1: R|kotlin/Int| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.inv|()
public get(): R|kotlin/Int|
public final val l1: R|kotlin/Long| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.inv|().R|kotlin/Int.toLong|()
public get(): R|kotlin/Long|
public final val ll1: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)).R|kotlin/Long.plus|(Int(1)).R|kotlin/Long.inv|()
public get(): R|kotlin/Long|
public final val i2: R|kotlin/Int| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.unaryPlus|()
public get(): R|kotlin/Int|
public final val l2: R|kotlin/Long| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.unaryPlus|().R|kotlin/Int.toLong|()
public get(): R|kotlin/Long|
public final val ll2: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)).R|kotlin/Long.plus|(Int(1)).R|kotlin/Long.unaryPlus|()
public get(): R|kotlin/Long|
public final val i3: R|kotlin/Int| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.unaryMinus|()
public get(): R|kotlin/Int|
public final val l3: R|kotlin/Long| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.unaryMinus|().R|kotlin/Int.toLong|()
public get(): R|kotlin/Long|
public final val ll3: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)).R|kotlin/Long.plus|(Int(1)).R|kotlin/Long.unaryMinus|()
public get(): R|kotlin/Long|
public final val i4: R|kotlin/Int| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.inc|()
public get(): R|kotlin/Int|
public final val l4: R|kotlin/Long| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).<CS errors: kotlin/Int.inc>#()
public get(): R|kotlin/Long|
public final val ll4: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)).R|kotlin/Long.plus|(Int(1)).R|kotlin/Long.inc|()
public get(): R|kotlin/Long|
public final val i5: R|kotlin/Int| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).R|kotlin/Int.dec|()
public get(): R|kotlin/Int|
public final val l5: R|kotlin/Long| = Int(2).R|kotlin/Int.plus|(Int(2).R|kotlin/Int.times|(Int(3))).<CS errors: kotlin/Int.dec>#()
public get(): R|kotlin/Long|
public final val ll5: R|kotlin/Long| = Long(3000000000).R|kotlin/Long.times|(Int(2)).R|kotlin/Long.plus|(Int(1)).R|kotlin/Long.dec|()
public get(): R|kotlin/Long|
@@ -0,0 +1,27 @@
// FIR_IDENTICAL
// SKIP_TXT
// FIR_DUMP
// ------------- const -------------
val i1 = (2 + 2 * 3).inv()
val l1: Long = (2 + 2 * 3).inv()
val ll1 = (3000000000 * 2 + 1).inv()
val i2 = (2 + 2 * 3).unaryPlus()
val l2: Long = (2 + 2 * 3).unaryPlus()
val ll2 = (3000000000 * 2 + 1).unaryPlus()
val i3 = (2 + 2 * 3).unaryMinus()
val l3: Long = (2 + 2 * 3).unaryMinus()
val ll3 = (3000000000 * 2 + 1).unaryMinus()
// ------------- non const -------------
val i4 = (2 + 2 * 3).inc()
val l4: Long = <!TYPE_MISMATCH!>(2 + 2 * 3).inc()<!>
val ll4 = (3000000000 * 2 + 1).inc()
val i5 = (2 + 2 * 3).dec()
val l5: Long = <!TYPE_MISMATCH!>(2 + 2 * 3).dec()<!>
val ll5 = (3000000000 * 2 + 1).dec()
@@ -14,15 +14,15 @@ fun testLongDotCall(c1: C<Long>) {
c1.takeT(1.rem(2))
c1.takeT(<!ARGUMENT_TYPE_MISMATCH!>1.inc()<!>)
c1.takeT(<!ARGUMENT_TYPE_MISMATCH!>1.dec()<!>)
c1.takeT(<!ARGUMENT_TYPE_MISMATCH!>1.unaryPlus()<!>)
c1.takeT(<!ARGUMENT_TYPE_MISMATCH!>1.unaryMinus()<!>)
c1.takeT(1.unaryPlus())
c1.takeT(1.unaryMinus())
c1.takeT(1.shl(2))
c1.takeT(1.shr(2))
c1.takeT(1.ushr(2))
c1.takeT(1.and(2))
c1.takeT(1.or(2))
c1.takeT(1.xor(2))
c1.takeT(<!ARGUMENT_TYPE_MISMATCH!>1.inv()<!>)
c1.takeT(1.inv())
}
fun testShortDotCall(c2: C<Short>) {
@@ -70,9 +70,9 @@ fun testLongUnaryOperators() {
takeLong(-1)
// Mismatch
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.unaryPlus()<!>)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.unaryMinus()<!>)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.inv()<!>)
takeLong(2.unaryPlus())
takeLong(2.unaryMinus())
takeLong(2.inv())
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.inc()<!>)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.dec()<!>)
}
@@ -68,9 +68,9 @@ fun testLongUnaryOperators() {
// Won't change
takeLong(+1)
takeLong(-1)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.unaryPlus()<!>)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.unaryMinus()<!>)
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.inv()<!>)
takeLong(2.unaryPlus())
takeLong(2.unaryMinus())
takeLong(2.inv())
// Will change
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.inc()<!>)