diff --git a/backend.native/tests/external/codegen/box/boxingOptimization/explicitEqualsOnDouble.kt b/backend.native/tests/external/codegen/box/boxingOptimization/explicitEqualsOnDouble.kt index ea864337add..d515e1d9db2 100644 --- a/backend.native/tests/external/codegen/box/boxingOptimization/explicitEqualsOnDouble.kt +++ b/backend.native/tests/external/codegen/box/boxingOptimization/explicitEqualsOnDouble.kt @@ -1,4 +1,5 @@ // IGNORE_BACKEND: JS +// IGNORE_BACKEND: NATIVE fun equals1(a: Double, b: Double) = a.equals(b) diff --git a/backend.native/tests/external/codegen/box/closures/capturedVarsOptimization/kt17588.kt b/backend.native/tests/external/codegen/box/closures/capturedVarsOptimization/kt17588.kt new file mode 100644 index 00000000000..44a84014aa5 --- /dev/null +++ b/backend.native/tests/external/codegen/box/closures/capturedVarsOptimization/kt17588.kt @@ -0,0 +1,30 @@ +//WITH_RUNTIME +class Test { + + data class Style( + val color: Int? = null, + val underlined: Boolean? = null, + val separator: String = "" + ) + + init { + var flag: Boolean? = null + + val receiver: String = "123" + try { + receiver.let { a2 -> + flag = false + } + } finally { + receiver.hashCode() + } + val style = Style(null, flag, "123") + } +} + + +fun box(): String { + Test() + + return "OK" +} \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt b/backend.native/tests/external/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt new file mode 100644 index 00000000000..21aa85b6baa --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/breakContinueInExpressions/kt17384.kt @@ -0,0 +1,26 @@ +fun returnNullable(): String? = null + +inline fun Array.matchAll(fn: (String) -> Unit) { + for (string in this) { + fn(returnNullable() ?: continue) + } +} + +fun Array.matchAll2(fn: (String) -> Unit) { + matchAll(fn) +} + +inline fun Array.matchAll3(crossinline fn: (String) -> Unit) { + matchAll2 { fn(it) } +} + +fun test(a: Array) { + a.matchAll {} + a.matchAll2 {} + a.matchAll3 {} +} + +fun box(): String { + test(arrayOf("")) + return "OK" +} \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/forInCharSequence.kt b/backend.native/tests/external/codegen/box/controlStructures/forInCharSequence.kt new file mode 100644 index 00000000000..f4df7137f60 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/forInCharSequence.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME + +fun box(): String { + var s = "" + for (c in StringBuilder("OK")) { + s += c + } + return s +} \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/forInCharSequenceMut.kt b/backend.native/tests/external/codegen/box/controlStructures/forInCharSequenceMut.kt new file mode 100644 index 00000000000..6f2b3414c02 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/forInCharSequenceMut.kt @@ -0,0 +1,19 @@ +// WITH_RUNTIME + +fun box(): String { + var clist = listOf('1', '2', '3', '4') + var res1 = "" + for (ch in clist) { + res1 += ch + clist = listOf() + } + + var s = "1234" + var res2 = "" + for (ch in s) { + res2 += ch + s = "" + } + + return if (res1 == res2) "OK" else "'$res1' != '$res2'" +} \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/kt17590.kt b/backend.native/tests/external/codegen/box/controlStructures/kt17590.kt new file mode 100644 index 00000000000..15dba9e8546 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/kt17590.kt @@ -0,0 +1,7 @@ +fun zap(s: String): String? = s + +inline fun tryZap(s: String, fn: (String) -> String): String { + return fn(zap(s) ?: return "null") +} + +fun box() = tryZap("OK") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/kt17590_long.kt b/backend.native/tests/external/codegen/box/controlStructures/kt17590_long.kt new file mode 100644 index 00000000000..521c7fd61cf --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/kt17590_long.kt @@ -0,0 +1,10 @@ +fun foo(x: Any?, y: Any?) = 0L + +inline fun test(value: Any?): Long { + return foo(null, value ?: return 1L) +} + +fun box(): String { + val t = test(null) + return if (t == 1L) "OK" else "fail: t=$t" +} \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572.kt new file mode 100644 index 00000000000..368df7ae6f9 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572.kt @@ -0,0 +1,6 @@ +fun zap(s: String) = s + +inline fun tryZap(string: String, fn: (String) -> String) = + fn(try { zap(string) } catch (e: Exception) { "" }) + +fun box(): String = tryZap("OK") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_2.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_2.kt new file mode 100644 index 00000000000..ed417d9b8bc --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_2.kt @@ -0,0 +1,9 @@ +fun zap(s: String) = s + +inline fun tryZap(s1: String, s2: String, fn: (String, String) -> String) = + fn( + try { zap(s1) } catch (e: Exception) { "" }, + try { zap(s2) } catch (e: Exception) { "" } + ) + +fun box(): String = tryZap("O", "K") { a, b -> a + b } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_2_ext.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_2_ext.kt new file mode 100644 index 00000000000..6f5cb1df234 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_2_ext.kt @@ -0,0 +1,9 @@ +fun zap(s: String) = s + +inline fun tryZap(s1: String, s2: String, fn: String.(String) -> String) = + fn( + try { zap(s1) } catch (e: Exception) { "" }, + try { zap(s2) } catch (e: Exception) { "" } + ) + +fun box(): String = tryZap("O", "K") { this + it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_ext.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_ext.kt new file mode 100644 index 00000000000..8e9066f7cc7 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_ext.kt @@ -0,0 +1,6 @@ +fun zap(s: String) = s + +inline fun tryZap(string: String, fn: String.() -> String) = + fn(try { zap(string) } catch (e: Exception) { "" }) + +fun box(): String = tryZap("OK") { this } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_nested.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_nested.kt new file mode 100644 index 00000000000..7d7467b0694 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17572_nested.kt @@ -0,0 +1,13 @@ +fun zap(s: String) = s + +inline fun tryZap(string: String, fn: (String) -> String) = + fn( + try { + try { + zap(string) + } + catch (e: Exception) { "" } + } catch (e: Exception) { "" } + ) + +fun box(): String = tryZap("OK") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17573.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17573.kt new file mode 100644 index 00000000000..de1d0b45cbc --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17573.kt @@ -0,0 +1,6 @@ +fun zap(s: String) = s + +inline fun tryZap(string: String, fn: (String) -> String) = + fn(try { zap(string) } finally {}) + +fun box(): String = tryZap("OK") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17573_nested.kt b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17573_nested.kt new file mode 100644 index 00000000000..e241aec5239 --- /dev/null +++ b/backend.native/tests/external/codegen/box/controlStructures/tryCatchInExpressions/kt17573_nested.kt @@ -0,0 +1,17 @@ +fun zap(s: String) = s + +inline fun tryZap1(string: String, fn: (String) -> String) = + fn( + try { zap(string) } finally { + try { zap(string) } finally { } + } + ) + +inline fun tryZap2(string: String, fn: (String) -> String) = + fn( + try { zap(string) } finally { + try { zap(string) } catch (e: Exception) { } + } + ) + +fun box(): String = tryZap1("O") { it } + tryZap2("K") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/box/regressions/kt6485.kt b/backend.native/tests/external/codegen/box/regressions/kt6485.kt index 563ed276949..0304fd25b83 100644 --- a/backend.native/tests/external/codegen/box/regressions/kt6485.kt +++ b/backend.native/tests/external/codegen/box/regressions/kt6485.kt @@ -18,8 +18,17 @@ inline fun typeLiteral(): TypeLiteral = object : TypeLiteral() fun box(): String { assertEquals("java.lang.String", (typeLiteral().type as Class<*>).canonicalName) assertEquals("java.util.List", typeLiteral>().type.toString()) - assertEquals("java.lang.String[]", (typeLiteral>().type as Class<*>).canonicalName) - assertEquals("java.lang.Integer[]", (typeLiteral>().type as Class<*>).canonicalName) - assertEquals("java.lang.String[][]", (typeLiteral>>().type as Class<*>).canonicalName) + + //note that 'type' implementation for next cases is different on jdk 6 and 8: GenericArrayType and Class + assertEquals("java.lang.String[]", typeLiteral>().type.canonicalName) + assertEquals("java.lang.Integer[]", typeLiteral>().type.canonicalName) + assertEquals("java.lang.String[][]", typeLiteral>>().type.canonicalName) return "OK" -} \ No newline at end of file +} + +val Type.canonicalName: String + get() = when (this) { + is Class<*> -> this.canonicalName + is java.lang.reflect.GenericArrayType -> this.getGenericComponentType().canonicalName + "[]" + else -> null!! + } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/boxInline/special/loopInStoreLoadChains.kt b/backend.native/tests/external/codegen/boxInline/special/loopInStoreLoadChains.kt new file mode 100644 index 00000000000..1d368d6595e --- /dev/null +++ b/backend.native/tests/external/codegen/boxInline/special/loopInStoreLoadChains.kt @@ -0,0 +1,19 @@ +// NO_CHECK_LAMBDA_INLINING + +// FILE: 1.kt +inline fun test(noinline foo: () -> String, noinline bar: () -> String): String { + var vfoo = foo + var vbar = bar + var vres = foo + for (i in 1 .. 4) { + vres = vbar + vbar = vfoo + vfoo = vres + } + return vres() +} + + +// FILE: 2.kt +fun box(): String = + test({ "OK" }, { "wrong lambda" }) \ No newline at end of file diff --git a/backend.native/tests/external/codegen/boxInline/special/loopInStoreLoadChains2.kt b/backend.native/tests/external/codegen/boxInline/special/loopInStoreLoadChains2.kt new file mode 100644 index 00000000000..9e0289e38d0 --- /dev/null +++ b/backend.native/tests/external/codegen/boxInline/special/loopInStoreLoadChains2.kt @@ -0,0 +1,25 @@ +// FILE: 1.kt +inline fun cycle(p: String): String { + var z = p + var x = z + for (i in 1..4) { + z = x + x = z + } + return z +} + +inline fun test(crossinline foo: String.() -> String): String { + val cycle = cycle("123"); + + { + cycle.foo() + }() + + + return cycle.foo() +} + + +// FILE: 2.kt +fun box(): String = test { "OK" } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591.kt b/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591.kt new file mode 100644 index 00000000000..c9a891f0e7d --- /dev/null +++ b/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591.kt @@ -0,0 +1,7 @@ +// FILE: 1.kt +inline fun alwaysOk(s: String, fn: (String) -> String): String { + return fn(return "OK") +} + +// FILE: 2.kt +fun box() = alwaysOk("what?") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591a.kt b/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591a.kt new file mode 100644 index 00000000000..adb5010e8c7 --- /dev/null +++ b/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591a.kt @@ -0,0 +1,7 @@ +// FILE: 1.kt +inline fun alwaysOk(s: String, fn: (String) -> String): String { + try { return fn(return "fail") } finally { fn(return "OK") } +} + +// FILE: 2.kt +fun box() = alwaysOk("what?") { it } \ No newline at end of file diff --git a/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591b.kt b/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591b.kt new file mode 100644 index 00000000000..672946db11d --- /dev/null +++ b/backend.native/tests/external/codegen/boxInline/stackOnReturn/kt17591b.kt @@ -0,0 +1,15 @@ +// FILE: 1.kt +inline fun alwaysOk(s: String, fn: (String) -> String): String { + try { + throw Exception() + } + catch(e: Exception) { + fn(return "fail") + } + finally { + fn(return "OK") + } +} + +// FILE: 2.kt +fun box() = alwaysOk("what?") { it } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index eb0b51fa3e7..98474275640 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,6 @@ minMacOsVersion = 10.11 remoteRoot=konan_tests #kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-SNAPSHOT # Download artifacts of https://teamcity.jetbrains.com/viewType.html?buildTypeId=bt345 -testDataVersion=1050294:id +testDataVersion=1053418:id kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-20170426.212805-507 konanVersion=0.1