tests for obsolete/fixed issues

#KT-1038 fixed
 #KT-1127 fixed
 #KT-1145 fixed
 #KT-1410 fixed
 #KT-1718 fixed
 #KT-2286 fixed
 #KT-1431 fixed
 #KT-2394 fixed
This commit is contained in:
Svetlana Isakova
2012-08-16 18:02:21 +04:00
parent fc858aec59
commit d2e33c8900
11 changed files with 245 additions and 9 deletions
@@ -0,0 +1,64 @@
//KT-1038 Cannot compile lazy iterators
class YieldingIterator<T>(val yieldingFunction : ()->T?) : Iterator<T>
{
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<T>(val yielderFactory : ()->(()->T?)) : Iterable<T>
{
override fun iterator(): Iterator<T> = YieldingIterator(yielderFactory())
}
public fun<TItem> Iterable<TItem>.lazy() : Iterable<TItem>
{
return YieldingIterable {
val iterator = this.iterator();
{ if (iterator.hasNext()) iterator.next() else null }
}
}
fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : Iterable<TItem>
{
return YieldingIterable {
val iterator = this.iterator()
fun yielder() : TItem? {
while(iterator.hasNext())
{
val next = iterator.next()
if (predicate(next))
return next
}
null
}
{ yielder() }
}
}
fun<TItem, TResult> Iterable<TItem>.select(selector : (TItem)->TResult) : Iterable<TResult>
{
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"
}
@@ -9,6 +9,16 @@ fun foo() {
val u = v map { it * 2 }
u : List<Int>
val a = 1..5
val b = a.map { it * 2 }
b : List<Int>
//check for non-error types
<!TYPE_MISMATCH!>u<!> : String
<!TYPE_MISMATCH!>b<!> : String
}
@@ -17,12 +27,6 @@ fun foo() {
fun <T> array(vararg t : T) : Array<T> = t
fun <T, R> Array<T>.map(transform : (T) -> R) : java.util.List<R> {
return mapTo(java.util.ArrayList<R>(this.size), transform)
}
fun <T, R> Array<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : java.util.List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T, R, C: Collection<in R>> Array<T>.mapTo(result: C, transform : (T) -> R) : C {
for (item in this)
result.add(transform(item))
return result
}
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : java.util.List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -0,0 +1,11 @@
//KT-1127 Wrong type computed for Arrays.asList()
package d
import java.util.List
fun <T> asList(<!UNUSED_PARAMETER!>t<!>: T) : List<T>? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun main(args : Array<String>) {
val <!UNUSED_VARIABLE!>list<!> : List<String> = <!TYPE_MISMATCH!>asList("")<!>
}
@@ -0,0 +1,13 @@
//KT-1145 removing explicit generics on a call to Iterable<T>.map(...) seems to generate an odd bytecode/runtime error
package d
fun test(numbers: Iterable<Int>) {
val s = numbers.map{it.toString()}.fold(""){(it, it2) -> it + it2}
<!TYPE_MISMATCH!>s<!>: Int
}
//from library
fun <T, R> Iterable<T>.map(<!UNUSED_PARAMETER!>transform<!> : (T) -> R) : java.util.List<R> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <T> Iterable<T>.fold(<!UNUSED_PARAMETER!>initial<!>: T, <!UNUSED_PARAMETER!>operation<!>: (T, T) -> T): T {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -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 <T> Collection<out T>.filterToMy(result : List<in T>, filter : (T) -> Boolean) : Collection<out T> {
for (t in this){
if (filter(t)){
result.add(t)
}
}
return this
}
fun foo(result: List<in String>, val collection: Collection<String>, prefix : String){
collection.filterToMy(result, {it.startsWith(prefix)})
}
fun test(result: List<in Any>, val collection: Collection<String>, prefix : String){
val c = collection.filterToMy(result, {it.startsWith(prefix)})
c: Collection<out String>
}
//from library
fun String.startsWith(<!UNUSED_PARAMETER!>prefix<!>: String) : Boolean {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -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<String>
//check it's not an error type
<!TYPE_MISMATCH!>list<!>: Int
}
//from library
fun arrayList<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : ArrayList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun <in T> Iterable<T>.plus(<!UNUSED_PARAMETER!>elements<!>: Iterable<T>): List<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -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<Int>
fun getThree(): Int? {
return coll.find{ it > 3 } // works fine
}
val anotherThree : Int
get() = <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // does not work here
val yetAnotherThree : Int
get() = <!TYPE_MISMATCH!>coll.find({ (v:Int) -> v > 3 })<!> // neither here
val extendedGetter : Int
get() {
return <!TYPE_MISMATCH!>coll.find{ it > 3 }<!> // not even here!
}
}
//from library
fun <T> Iterable<T>.find(<!UNUSED_PARAMETER!>predicate<!>: (T) -> Boolean) : T? {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -0,0 +1,17 @@
//FILE: a/C.java
// KT-1431 StackOverflowException in IDE when using JavaFX builders
package a;
public class C<B extends C<B>> {
public static C<?> create() { return null; }
public C foo() {return null;}
}
//FILE: d.kt
package d
import a.C
fun test() {
C.create()<!UNSAFE_CALL!>.<!>foo()
}
@@ -0,0 +1,15 @@
//KT-2394 java.lang.Iterable<T> should be visible as jet.Iterable<out T>
package d
import java.util.Collection
fun foo(iterable: Iterable<Int>, iterator: Iterator<Int>, comparable: Comparable<Any>) {
iterable : Iterable<Any>
iterator : Iterator<Any>
comparable : Comparable<String>
}
fun bar(c: Collection<Int>) {
c : Iterable<Any>
c.iterator() : Iterator<Any>
}
@@ -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");
@@ -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");