diff --git a/compiler/testData/codegen/regressions/kt1038.kt b/compiler/testData/codegen/regressions/kt1038.kt new file mode 100644 index 00000000000..5c7046bfa41 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1038.kt @@ -0,0 +1,64 @@ +//KT-1038 Cannot compile lazy iterators + +class YieldingIterator(val yieldingFunction : ()->T?) : Iterator +{ + var current : T? = yieldingFunction() + override fun next(): T { + val next = current; + if (next != null) + { + current = yieldingFunction() + return next + } + else throw IndexOutOfBoundsException() + } + override fun hasNext(): Boolean = current != null +} + +class YieldingIterable(val yielderFactory : ()->(()->T?)) : Iterable +{ + override fun iterator(): Iterator = YieldingIterator(yielderFactory()) +} + +public fun Iterable.lazy() : Iterable + { + return YieldingIterable { + val iterator = this.iterator(); + { if (iterator.hasNext()) iterator.next() else null } + } + } + +fun Iterable.where(predicate : (TItem)->Boolean) : Iterable + { + return YieldingIterable { + val iterator = this.iterator() + fun yielder() : TItem? { + while(iterator.hasNext()) + { + val next = iterator.next() + if (predicate(next)) + return next + } + null + } + { yielder() } + } + } + +fun Iterable.select(selector : (TItem)->TResult) : Iterable + { + return YieldingIterable { + val iterator = this.iterator(); + { if(iterator.hasNext()) selector(iterator.next()) else null } + } + } + +fun box() : String { + val x = 0..100 + val filtered = x where { it % 2 == 0 } + val xx = x select { it * 2 } + var res = 0 + for (val x in xx) + res += x + return if (res == 10100) "OK" else "fail" +} diff --git a/compiler/testData/diagnostics/tests/inference/mapFunction.kt b/compiler/testData/diagnostics/tests/inference/mapFunction.kt index 74bac13367c..ba0b42dbcc3 100644 --- a/compiler/testData/diagnostics/tests/inference/mapFunction.kt +++ b/compiler/testData/diagnostics/tests/inference/mapFunction.kt @@ -9,6 +9,16 @@ fun foo() { val u = v map { it * 2 } u : List + + val a = 1..5 + + val b = a.map { it * 2 } + + b : List + + //check for non-error types + u : String + b : String } @@ -17,12 +27,6 @@ fun foo() { fun array(vararg t : T) : Array = t -fun Array.map(transform : (T) -> R) : java.util.List { - return mapTo(java.util.ArrayList(this.size), transform) -} +fun Array.map(transform : (T) -> R) : java.util.List {} -fun > Array.mapTo(result: C, transform : (T) -> R) : C { - for (item in this) - result.add(transform(item)) - return result -} +fun Iterable.map(transform : (T) -> R) : java.util.List {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt new file mode 100644 index 00000000000..aafb168960c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt @@ -0,0 +1,11 @@ +//KT-1127 Wrong type computed for Arrays.asList() + +package d + +import java.util.List + +fun asList(t: T) : List? {} + +fun main(args : Array) { + val list : List = asList("") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1145.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1145.kt new file mode 100644 index 00000000000..96fd76aa83f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1145.kt @@ -0,0 +1,13 @@ +//KT-1145 removing explicit generics on a call to Iterable.map(...) seems to generate an odd bytecode/runtime error + +package d + +fun test(numbers: Iterable) { + val s = numbers.map{it.toString()}.fold(""){(it, it2) -> it + it2} + s: Int +} + +//from library +fun Iterable.map(transform : (T) -> R) : java.util.List {} + +fun Iterable.fold(initial: T, operation: (T, T) -> T): T {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1410.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1410.kt new file mode 100644 index 00000000000..fd6db81a874 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1410.kt @@ -0,0 +1,27 @@ +// KT-1410 Compiler does automatically infer type argument when using variance +//+JDK +package d + +import java.util.Collection +import java.util.List + +public fun Collection.filterToMy(result : List, filter : (T) -> Boolean) : Collection { + for (t in this){ + if (filter(t)){ + result.add(t) + } + } + return this +} + +fun foo(result: List, val collection: Collection, prefix : String){ + collection.filterToMy(result, {it.startsWith(prefix)}) +} + +fun test(result: List, val collection: Collection, prefix : String){ + val c = collection.filterToMy(result, {it.startsWith(prefix)}) + c: Collection +} + +//from library +fun String.startsWith(prefix: String) : Boolean {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1718.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1718.kt new file mode 100644 index 00000000000..1ec0751d434 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1718.kt @@ -0,0 +1,16 @@ +//KT-1718 compiler error when not using temporary variable +package n + +import java.util.List +import java.util.ArrayList + +fun test() { + val list = arrayList("foo", "bar") + arrayList("cheese", "wine") + list: List + //check it's not an error type + list: Int +} + +//from library +fun arrayList(vararg values: T) : ArrayList {} +fun Iterable.plus(elements: Iterable): List {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt new file mode 100644 index 00000000000..1c2ba422f10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt @@ -0,0 +1,27 @@ +// KT-2286 Improve error message for nullability check failure for extension methods + +package n + +abstract class Buggy { + + abstract val coll : java.util.Collection + + fun getThree(): Int? { + return coll.find{ it > 3 } // works fine + } + + val anotherThree : Int + get() = coll.find{ it > 3 } // does not work here + + val yetAnotherThree : Int + get() = coll.find({ (v:Int) -> v > 3 }) // neither here + + val extendedGetter : Int + get() { + return coll.find{ it > 3 } // not even here! + } + +} + +//from library +fun Iterable.find(predicate: (T) -> Boolean) : T? {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt1431.kt b/compiler/testData/diagnostics/tests/j+k/kt1431.kt new file mode 100644 index 00000000000..81a9d85a805 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt1431.kt @@ -0,0 +1,17 @@ +//FILE: a/C.java +// KT-1431 StackOverflowException in IDE when using JavaFX builders +package a; + +public class C> { + public static C create() { return null; } + public C foo() {return null;} +} + +//FILE: d.kt +package d + +import a.C + +fun test() { + C.create().foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/kt2394.kt b/compiler/testData/diagnostics/tests/j+k/kt2394.kt new file mode 100644 index 00000000000..bd12781a8d3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/kt2394.kt @@ -0,0 +1,15 @@ +//KT-2394 java.lang.Iterable should be visible as jet.Iterable +package d + +import java.util.Collection + +fun foo(iterable: Iterable, iterator: Iterator, comparable: Comparable) { + iterable : Iterable + iterator : Iterator + comparable : Comparable +} + +fun bar(c: Collection) { + c : Iterable + c.iterator() : Iterator +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index ddbaa7a0792..d9a686b00b0 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -15,12 +15,15 @@ */ package org.jetbrains.jet.checkers; +import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestSuite; + +import java.io.File; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.test.TestMetadata; -import java.io.File; +import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve; /** This class is generated by {@link org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve}. DO NOT MODIFY MANUALLY */ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEagerResolve { @@ -1362,11 +1365,31 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1031.kt"); } + @TestMetadata("kt1127.kt") + public void testKt1127() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt"); + } + + @TestMetadata("kt1145.kt") + public void testKt1145() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1145.kt"); + } + + @TestMetadata("kt1410.kt") + public void testKt1410() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1410.kt"); + } + @TestMetadata("kt1558.kt") public void testKt1558() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1558.kt"); } + @TestMetadata("kt1718.kt") + public void testKt1718() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1718.kt"); + } + @TestMetadata("kt1944.kt") public void testKt1944() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt1944.kt"); @@ -1387,6 +1410,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt"); } + @TestMetadata("kt2286.kt") + public void testKt2286() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt"); + } + @TestMetadata("kt2294.kt") public void testKt2294() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2294.kt"); @@ -1501,6 +1529,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/j+k/kt1402.kt"); } + @TestMetadata("kt1431.kt") + public void testKt1431() throws Exception { + doTest("compiler/testData/diagnostics/tests/j+k/kt1431.kt"); + } + + @TestMetadata("kt2394.kt") + public void testKt2394() throws Exception { + doTest("compiler/testData/diagnostics/tests/j+k/kt2394.kt"); + } + @TestMetadata("OverrideVararg.kt") public void testOverrideVararg() throws Exception { doTest("compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt"); diff --git a/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java index 6b33773c522..846a3edef86 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java @@ -159,6 +159,10 @@ public class FunctionGenTest extends CodegenTestCase { generateToText(); } + public void testKt1038() { + blackBoxFile("regressions/kt1038.kt"); + } + public static class WithJavaFunctionGenTest extends CodegenTestCase { private void blackBoxFileWithJava(@NotNull String ktFile) throws Exception { File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes");