backend: enable and add tests for autoboxing

This commit is contained in:
Svyatoslav Scherbina
2016-12-19 14:58:54 +07:00
committed by SvyatoslavScherbina
parent 61c28db886
commit f2b5b98dba
12 changed files with 179 additions and 2 deletions
+57 -2
View File
@@ -464,11 +464,66 @@ task boxing0(type: RunKonanTest) {
source = "codegen/boxing/boxing0.kt"
}
task boxing1 (type:RunKonanTest) {
disabled = true
task boxing1(type: RunKonanTest) {
goldValue = "1\nfalse\nHello\n"
source = "codegen/boxing/boxing1.kt"
}
task boxing2(type: RunKonanTest) {
goldValue = "1\ntrue\nother\n"
source = "codegen/boxing/boxing2.kt"
}
task boxing3(type: RunKonanTest) {
goldValue = "42\n"
source = "codegen/boxing/boxing3.kt"
}
task boxing4(type: RunKonanTest) {
goldValue = "16\n"
source = "codegen/boxing/boxing4.kt"
}
task boxing5(type: RunKonanTest) {
goldValue = "16\n42\n"
source = "codegen/boxing/boxing5.kt"
}
task boxing6(type: RunKonanTest) {
goldValue = "42\n16\n"
source = "codegen/boxing/boxing6.kt"
}
task boxing7(type: RunKonanTest) {
goldValue = "1\n0\n"
source = "codegen/boxing/boxing7.kt"
}
task boxing8(type: RunKonanTest) {
goldValue = "1\n<null>\ntrue\nHello\n"
source = "codegen/boxing/boxing8.kt"
}
task boxing9(type: RunKonanTest) {
goldValue = "1\n<null>\ntrue\nHello\n2\n<null>\ntrue\nHello\n3\n"
source = "codegen/boxing/boxing9.kt"
}
task boxing10(type: RunKonanTest) {
goldValue = "Ok\n"
source = "codegen/boxing/boxing10.kt"
}
task boxing11(type: RunKonanTest) {
goldValue = "17\n42\n"
source = "codegen/boxing/boxing11.kt"
}
task boxing12(type: RunKonanTest) {
goldValue = "18\n"
source = "codegen/boxing/boxing12.kt"
}
task interface0(type: RunKonanTest) {
goldValue = "PASSED\n"
source = "runtime/basic/interface0.kt"
@@ -0,0 +1,9 @@
fun main(args: Array<String>) {
val FALSE: Boolean? = false
if (FALSE != null) {
do {
println("Ok")
} while (FALSE)
}
}
@@ -0,0 +1,12 @@
fun printInt(x: Int) = println(x)
class Foo(val value: Int?) {
fun foo() {
printInt(if (value != null) value else 42)
}
}
fun main(args: Array<String>) {
Foo(17).foo()
Foo(null).foo()
}
@@ -0,0 +1,7 @@
fun foo(x: Number) {
println(x.toByte())
}
fun main(args: Array<String>) {
foo(18)
}
@@ -0,0 +1,17 @@
fun printInt(x: Int) = println(x)
fun printBoolean(x: Boolean) = println(x)
fun foo(arg: Any) {
if (arg is Int)
printInt(arg)
else if (arg is Boolean)
printBoolean(arg)
else
println("other")
}
fun main(args: Array<String>) {
foo(1)
foo(true)
foo("Hello")
}
@@ -0,0 +1,10 @@
fun printInt(x: Int) = println(x)
fun foo(arg: Int?) {
if (arg != null)
printInt(arg)
}
fun main(args: Array<String>) {
foo(42)
}
@@ -0,0 +1,10 @@
fun printInt(x: Int) = println(x)
fun foo(arg: Any?) {
if (arg is Int? && arg != null)
printInt(arg)
}
fun main(args: Array<String>) {
foo(16)
}
@@ -0,0 +1,10 @@
fun printInt(x: Int) = println(x)
fun foo(arg: Int?) {
printInt(arg ?: 16)
}
fun main(args: Array<String>) {
foo(null)
foo(42)
}
@@ -0,0 +1,10 @@
fun printInt(x: Int) = println(x)
fun foo(arg: Any) {
printInt(arg as? Int ?: 16)
}
fun main(args: Array<String>) {
foo(42)
foo("Hello")
}
@@ -0,0 +1,15 @@
fun printInt(x: Int) = println(x)
fun foo(arg: Any) {
val argAsInt = try {
arg as Int
} catch (e: ClassCastException) {
0
}
printInt(argAsInt)
}
fun main(args: Array<String>) {
foo(1)
foo("Hello")
}
@@ -0,0 +1,9 @@
fun foo(vararg args: Any?) {
for (arg in args) {
println(arg.toString())
}
}
fun main(args: Array<String>) {
foo(1, null, true, "Hello")
}
@@ -0,0 +1,13 @@
fun foo(vararg args: Any?) {
for (arg in args) {
println(arg.toString())
}
}
fun bar(vararg args: Any?) {
foo(1, *args, 2, *args, 3)
}
fun main(args: Array<String>) {
bar(null, true, "Hello")
}