Postfix expression code generation fixed as per KT-7561.

A set of tests for KT-7561 on codegen side, including exotic inc() functions().
 #KT-7561 Fixed.
This commit is contained in:
Mikhail Glukhikh
2015-04-23 18:09:27 +03:00
parent 5723c2a077
commit 4570872bfd
17 changed files with 258 additions and 2 deletions
@@ -0,0 +1,8 @@
public fun box() : String {
var i : Int?
i = 10
// assignPlus on a smart cast should work
i += 1
return if (11 == i) "OK" else "fail i = $i"
}
@@ -0,0 +1,10 @@
public fun box() : String {
var i : Int?
i = 10
// We have "double" smart cast here:
// first on i and second on i++
// Back-end should NOT think that both i and j are Int
val j: Int = i++
return if (j == 10 && 11 == i) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,12 @@
trait Base
class Derived: Base
class Another: Base
fun Base.inc(): Derived { return Derived() }
public fun box() : String {
var i : Base
i = Another()
val j = i++
return if (j is Another && i is Derived) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,11 @@
open class Base
class Derived: Base()
fun Derived.inc(): Derived { return Derived() }
public fun box() : String {
var i : Base
i = Derived()
val j = i++
return if (j is Derived && i is Derived) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,8 @@
public fun box() : String {
var i : Short?
i = 10
// Postfix increment on a smart casted short should work
val j = i++
return if (j!!.toInt() == 10 && i!!.toInt() == 11) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,9 @@
public fun box() : String {
var i : Int?
i = 10
// Postfix increment on a smart cast should work
// Specific: i.inc() type is Int but i and j types are both Int?
val j = i++
return if (j == 10 && 11 == i) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,12 @@
class MyClass
// In principle it is not correct, MyClass? is not a subtype of MyClass
fun MyClass.inc(): MyClass? = null
public fun box() : String {
var i : MyClass?
i = MyClass()
val j = i++
return if (j is MyClass && null == i) "OK" else "fail i = $i j = $j"
}
@@ -0,0 +1,11 @@
class MyClass
fun MyClass?.inc(): MyClass? = null
public fun box() : String {
var i : MyClass?
i = MyClass()
val j = i++
return if (j is MyClass && null == i) "OK" else "fail i = $i j = $j"
}
@@ -0,0 +1,10 @@
fun Int?.inc(): Int? = this
fun init(): Int? { return 10 }
public fun box() : String {
var i : Int? = init()
val j = i++
return if (j == 10 && 10 == i) "OK" else "fail i = $i j = $j"
}
@@ -0,0 +1,12 @@
trait Base
class Derived: Base
class Another: Base
fun Base.inc(): Derived { return Derived() }
public fun box() : String {
var i : Base
i = Another()
val j = ++i
return if (j is Derived && i is Derived) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,11 @@
open class Base
class Derived: Base()
fun Derived.inc(): Derived { return Derived() }
public fun box() : String {
var i : Base
i = Derived()
val j = ++i
return if (j is Derived && i is Derived) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,8 @@
public fun box() : String {
var i : Int?
i = 10
// Prefix increment on a smart cast should work
val j = ++i
return if (j == 11 && 11 == i) "OK" else "fail j = $j i = $i"
}
@@ -0,0 +1,12 @@
class MyClass
// In principle it is not correct, MyClass? is not a subtype of MyClass
fun MyClass.inc(): MyClass? = null
public fun box() : String {
var i : MyClass?
i = MyClass()
val j = ++i
return if (j == null && null == i) "OK" else "fail i = $i j = $j"
}
@@ -0,0 +1,11 @@
class MyClass
fun MyClass?.inc(): MyClass? = null
public fun box() : String {
var i : MyClass?
i = MyClass()
val j = ++i
return if (j == null && null == i) "OK" else "fail i = $i j = $j"
}
@@ -0,0 +1,10 @@
fun Int?.inc(): Int? = this
fun init(): Int? { return 10 }
public fun box() : String {
var i : Int? = init()
val j = ++i
return if (j == 10 && 10 == i) "OK" else "fail i = $i j = $j"
}