From 8b918ef1aa8cc3482f64feedeb3938b0699a394c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 13 Feb 2014 04:41:38 +0400 Subject: [PATCH] Add regression tests for obsolete issues #KT-1291 Obsolete #KT-2895 Obsolete #KT-3060 Obsolete #KT-3298 Obsolete #KT-3613 Obsolete #KT-3862 Obsolete --- .../testData/codegen/box/classes/kt3862.kt | 18 +++++++++++ .../defaultArguments/constructor/kt3060.kt | 10 +++++++ .../codegen/box/extensionFunctions/kt3298.kt | 13 ++++++++ .../testData/codegen/box/functions/kt1291.kt | 27 +++++++++++++++++ .../box/functions/localFunctions/kt2895.kt | 15 ++++++++++ .../codegen/box/primitiveTypes/kt3613.kt | 6 ++++ .../BlackBoxCodegenTestGenerated.java | 30 +++++++++++++++++++ 7 files changed, 119 insertions(+) create mode 100644 compiler/testData/codegen/box/classes/kt3862.kt create mode 100644 compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt create mode 100644 compiler/testData/codegen/box/extensionFunctions/kt3298.kt create mode 100644 compiler/testData/codegen/box/functions/kt1291.kt create mode 100644 compiler/testData/codegen/box/functions/localFunctions/kt2895.kt create mode 100644 compiler/testData/codegen/box/primitiveTypes/kt3613.kt diff --git a/compiler/testData/codegen/box/classes/kt3862.kt b/compiler/testData/codegen/box/classes/kt3862.kt new file mode 100644 index 00000000000..c6d52a45fc4 --- /dev/null +++ b/compiler/testData/codegen/box/classes/kt3862.kt @@ -0,0 +1,18 @@ +open class A { + open fun foo(a: T): Int = 2 +} + +trait B : A { + override fun foo(a: T): Int = 1 +} + +class D : B, A() { + fun boo(): Int { + return super.foo(1) + } +} + +fun box(): String { + if (D().boo() != 1) return "Fail" + return "OK" +} diff --git a/compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt b/compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt new file mode 100644 index 00000000000..c5535da8aae --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt @@ -0,0 +1,10 @@ +class Foo private(val param: String = "OK") { + class object { + val s = Foo() + } +} + +fun box(): String { + Foo.s.param + return "OK" +} diff --git a/compiler/testData/codegen/box/extensionFunctions/kt3298.kt b/compiler/testData/codegen/box/extensionFunctions/kt3298.kt new file mode 100644 index 00000000000..24aba423880 --- /dev/null +++ b/compiler/testData/codegen/box/extensionFunctions/kt3298.kt @@ -0,0 +1,13 @@ +var result = "" +fun result(r: String) { result = r } + +object Foo { + private fun String.plus() = "(" + this + ")" + + fun foo() = { result(+"Stuff") }() +} + +fun box(): String { + Foo.foo() + return if (result == "(Stuff)") "OK" else "Fail $result" +} diff --git a/compiler/testData/codegen/box/functions/kt1291.kt b/compiler/testData/codegen/box/functions/kt1291.kt new file mode 100644 index 00000000000..02b5fd89707 --- /dev/null +++ b/compiler/testData/codegen/box/functions/kt1291.kt @@ -0,0 +1,27 @@ +var result = 0 + +fun Iterator.foreach(action: (T) -> Unit) { + while (this.hasNext()) { + (action)(this.next()) + } +} + +fun Iterator.select(f: (In) -> Out) : Iterator { + return Selector(this, f); +} + +class Selector(val source: Iterator, val f: (In) -> Out) : Iterator { + override fun hasNext(): Boolean = source.hasNext() + + override fun next(): Out { + return (f)(source.next()) + } +} + +fun box(): String { + Array(4, { it + 1 }).iterator() + .select({i -> i * 10}) + .foreach({k -> result += k}) + if (result != 10+20+30+40) return "Fail: $result" + return "OK" +} diff --git a/compiler/testData/codegen/box/functions/localFunctions/kt2895.kt b/compiler/testData/codegen/box/functions/localFunctions/kt2895.kt new file mode 100644 index 00000000000..58d122e489d --- /dev/null +++ b/compiler/testData/codegen/box/functions/localFunctions/kt2895.kt @@ -0,0 +1,15 @@ +fun outer() { + fun inner(i: Int) { + if (i > 0){ + { + (it: Int) -> inner(0) // <- invocation of literal itself is generated instead + }.invoke(1) + } + } + inner(1) +} + +fun box(): String { + outer() + return "OK" +} diff --git a/compiler/testData/codegen/box/primitiveTypes/kt3613.kt b/compiler/testData/codegen/box/primitiveTypes/kt3613.kt new file mode 100644 index 00000000000..c578f93fb7e --- /dev/null +++ b/compiler/testData/codegen/box/primitiveTypes/kt3613.kt @@ -0,0 +1,6 @@ +fun foo(): Int? = 42 + +fun box(): String { + if (foo()!! > 239) return "Fail" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 274607ff8ee..67311d194da 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -1241,6 +1241,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/classes/kt3546.kt"); } + @TestMetadata("kt3862.kt") + public void testKt3862() throws Exception { + doTest("compiler/testData/codegen/box/classes/kt3862.kt"); + } + @TestMetadata("kt454.kt") public void testKt454() throws Exception { doTest("compiler/testData/codegen/box/classes/kt454.kt"); @@ -1974,6 +1979,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/defaultArguments/constructor/kt2852.kt"); } + @TestMetadata("kt3060.kt") + public void testKt3060() throws Exception { + doTest("compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt"); + } + } @TestMetadata("compiler/testData/codegen/box/defaultArguments/function") @@ -2391,6 +2401,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/extensionFunctions/kt1953_class.kt"); } + @TestMetadata("kt3298.kt") + public void testKt3298() throws Exception { + doTest("compiler/testData/codegen/box/extensionFunctions/kt3298.kt"); + } + @TestMetadata("kt3646.kt") public void testKt3646() throws Exception { doTest("compiler/testData/codegen/box/extensionFunctions/kt3646.kt"); @@ -2732,6 +2747,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/functions/kt1199.kt"); } + @TestMetadata("kt1291.kt") + public void testKt1291() throws Exception { + doTest("compiler/testData/codegen/box/functions/kt1291.kt"); + } + @TestMetadata("kt1413.kt") public void testKt1413() throws Exception { doTest("compiler/testData/codegen/box/functions/kt1413.kt"); @@ -2876,6 +2896,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/box/functions/localFunctions"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("kt2895.kt") + public void testKt2895() throws Exception { + doTest("compiler/testData/codegen/box/functions/localFunctions/kt2895.kt"); + } + @TestMetadata("kt3978.kt") public void testKt3978() throws Exception { doTest("compiler/testData/codegen/box/functions/localFunctions/kt3978.kt"); @@ -4316,6 +4341,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/primitiveTypes/kt3576.kt"); } + @TestMetadata("kt3613.kt") + public void testKt3613() throws Exception { + doTest("compiler/testData/codegen/box/primitiveTypes/kt3613.kt"); + } + @TestMetadata("kt4097.kt") public void testKt4097() throws Exception { doTest("compiler/testData/codegen/box/primitiveTypes/kt4097.kt");