Move blackBoxFile() testData to box/ directory

Delete all test methods (and empty test classes), since they'll be
auto-generated
This commit is contained in:
Alexander Udalov
2013-01-25 16:13:45 +04:00
committed by Alexander Udalov
parent ecbb2f10ef
commit 41a416da60
438 changed files with 156 additions and 2005 deletions
@@ -1,7 +0,0 @@
fun box(): String {
return justPrint(9 compareTo 4)
}
fun justPrint(value: Int): String {
return if (value > 0) "OK" else "Fail $value"
}
@@ -1,6 +0,0 @@
val Int.test = "test"
fun box(): String {
val x = "a ${1.test}"
return if (x == "a test") "OK" else "Fail $x"
}
@@ -1,6 +0,0 @@
fun box(): String {
if (1 != 0) {
1
}
return "OK"
}
@@ -1,12 +0,0 @@
public class StockMarketTableModel() {
public fun getColumnCount() : Int {
return COLUMN_TITLES?.size!!
}
class object {
private val COLUMN_TITLES : Array<Int?> = arrayOfNulls<Int>(10)
}
}
fun box() : String = if(StockMarketTableModel().getColumnCount()==10) "OK" else "fail"
@@ -1,64 +0,0 @@
//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"
}
@@ -1,13 +0,0 @@
public open class Test() {
open public fun test() : Unit {
System.out?.println(hello)
}
class object {
private val hello : String? = "Hello"
}
}
fun box() : String {
Test().test()
return "OK"
}
@@ -1,17 +0,0 @@
fun box() : String {
return if(true.and(true)) "OK" else "fail"
}
fun Boolean.and(other : Boolean) : Boolean{
if(other == true) {
if(this == true){
return true ;
}
else{
return false;
}
}
else {
return false;
}
}
@@ -1,6 +0,0 @@
fun box() : String {
val a = "lala"
if(!a.identityEquals(a)) return "fail 1"
if(a identityEquals a) return "OK"
return "fail 2"
}
@@ -1,7 +0,0 @@
//KT-1061 Can't call function defined as a val
object X {
val doit = { (i: Int) -> i }
}
fun box() : String = if (X.doit(3) == 3) "OK" else "fail"
@@ -1,8 +0,0 @@
val f : (Any) -> String = { it.toString() }
fun box() : String {
if(!(f identityEquals f)) return "fail 1"
if(!(f == f)) return "fail 2"
if(!(f equals f)) return "fail 3"
return "OK"
}
@@ -1,12 +0,0 @@
enum class Direction() {
NORTH {
val someSpecialValue = "OK"
override fun f() = someSpecialValue
}
abstract fun f():String
}
fun box() = Direction.NORTH.f()
@@ -1,14 +0,0 @@
object RefreshQueue {
val workerThread: Thread = Thread(object : Runnable {
override fun run() {
val a = workerThread
val b = RefreshQueue.workerThread
if (a != b) throw AssertionError()
}
})
}
fun box() : String {
RefreshQueue.workerThread.run()
return "OK"
}
@@ -1,7 +0,0 @@
public class SomeClass() : java.lang.Object() {
}
public fun box():String {
System.out?.println(SomeClass().getClass())
return "OK"
}
@@ -1,50 +0,0 @@
import java.util.ArrayList
public object SomeObject {
private val workerThread = object : Thread() {
override fun run() {
foo()
}
}
{
workerThread.start()
}
private fun foo() : Unit {
}
}
public class SomeClass() {
inner class Inner {
val copy = list
}
private val list = ArrayList<String>()
var status : Throwable? = null
private val workerThread = object : Thread() {
public override fun run() {
try {
list.add("123")
list.add("33")
Inner().copy.add("444")
}
catch(t: Throwable) {
status = t
}
}
}
{
workerThread.start()
workerThread.join()
}
}
public fun box():String {
var obj = SomeClass()
return if(obj.status == null) "OK" else {
obj.status?.printStackTrace()
"failed"
}
}
@@ -1,28 +0,0 @@
public object SomeClass {
var bug: Any = ""
private val workerThread = object : Thread() {
override fun run() {
try {
foo()
bug = "none"
}
catch(t: Throwable) {
bug = t
}
}
}
{
workerThread.start()
}
private fun foo() : Unit {
}
}
public fun box():String {
if(SomeClass.bug is Throwable)
throw SomeClass.bug as Throwable
return "OK"
}
@@ -1,16 +0,0 @@
public object RefreshQueue {
private val workerThread: Thread = Thread(object : Runnable {
override fun run() {
workerThread.isInterrupted()
}
});
{
workerThread.start()
}
}
fun box() : String {
RefreshQueue
return "OK"
}
@@ -1,13 +0,0 @@
public abstract class VirtualFile() {
public abstract val size : Long
}
public class PhysicalVirtualFile : VirtualFile() {
public override val size: Long
get() = 11
}
fun box() : String {
PhysicalVirtualFile()
return "OK"
}
@@ -1,15 +0,0 @@
public abstract class BaseClass() {
protected abstract val kind : String
protected open val kind2 : String = " kind1"
fun debug() = kind + kind2
}
public class Subclass : BaseClass() {
override val kind : String = "Physical"
override val kind2 : String = " kind2"
}
fun box():String = if(Subclass().debug() == "Physical kind2") "OK" else "fail"
@@ -1,16 +0,0 @@
public abstract class BaseClass() {
open val kind : String = "BaseClass "
fun getKindValue() : String {
return kind
}
}
public class Subclass : BaseClass() {
override val kind : String = "Subclass "
}
fun box(): String {
val r = Subclass().getKindValue() + Subclass().kind
return if(r == "Subclass Subclass ") "OK" else "fail"
}
@@ -1,28 +0,0 @@
enum class Color(val rgb : Int) {
RED : Color(0xFF0000)
GREEN : Color(0x00FF00)
BLUE : Color(0x0000FF)
}
enum class Direction {
NORTH
SOUTH
WEST
EAST
}
fun bar(c: Color) = when (c) {
Color.RED -> 1
Color.GREEN -> 2
Color.BLUE -> 3
}
fun foo(d: Direction) = when(d) {
Direction.NORTH -> 1
Direction.SOUTH -> 2
Direction.WEST -> 3
Direction.EAST -> 4
}
fun box() : String =
if (foo(Direction.EAST) == 4 && bar(Color.GREEN) == 2) "OK" else "fail"
@@ -1,21 +0,0 @@
fun <T : Any> T?.iterator() = object {
var hasNext = this@iterator != null
private set
fun hasNext() = hasNext
fun next() : T {
if (hasNext) {
hasNext = false
return this@iterator!!
}
throw java.util.NoSuchElementException()
}
}
fun box() : String {
var k = 0
for (i in 1) {
k++
}
return if(k == 1) "OK" else "fail"
}
@@ -1,6 +0,0 @@
fun f(a : Int?, b : Int.(Int)->Int) = a?.b(1)
fun box(): String {
val x = f(1) { this+it+2 }
return if (x == 4) "OK" else "fail"
}
@@ -1,12 +0,0 @@
//KT-1249 IllegalStateException invoking function property
class TestClass(val body : () -> Unit) : Any() {
fun run() {
body()
}
}
fun box() : String {
TestClass({}).run()
return "OK"
}
@@ -1,14 +0,0 @@
//KT-1290 Method property in constructor causes NPE
class Foo<T>(val filter: (T) -> Boolean) {
public fun bar(tee: T) : Boolean {
return filter(tee);
}
}
fun foo() = Foo({ (i: Int) -> i < 5 }).bar(2)
fun box() : String {
if (!foo()) return "fail"
return "OK"
}
@@ -1,13 +0,0 @@
trait Creator<T> {
fun create() : T
}
class Actor(val code: String = "OK")
trait Factory : Creator<Actor>
class MyFactory() : Factory {
override fun create(): Actor = Actor()
}
fun box() : String = MyFactory().create().code
@@ -1,7 +0,0 @@
open class Base(val bar: String)
class Foo(bar: String) : Base(bar) {
fun something() = (bar as java.lang.String).toUpperCase()
}
fun box() = Foo("ok").something()
@@ -1,26 +0,0 @@
package t
trait I{
fun f()
}
class Test{
fun foo(){
val i : I = object : I {
override fun f() {
fun local(){
bar()
}
local()
}
}
i.f()
}
fun bar(){}
}
fun box() : String {
Test().foo()
return "OK"
}
@@ -1,9 +0,0 @@
package pack
open class A(val value: String )
class B(value: String) : A(value) {
fun toString() = "B($value)";
}
fun box() = if (B("4").toString() == "B(4)") "OK" else "fail"
@@ -1,17 +0,0 @@
class MyClass(var fnc : () -> String) {
fun test(): String {
return fnc()
}
}
fun printtest() : String {
return "OK"
}
fun box(): String {
var c = MyClass({ printtest() })
return c.test()
}
@@ -1,16 +0,0 @@
class Foo {
var rnd = 10
public fun equals(that : Any) : Boolean = that is Foo && (that.rnd == rnd)
}
fun box() : String {
val a = Foo()
val b = Foo()
if (!a.identityEquals(a)) return "fail 1"
if (!b.identityEquals(b)) return "fail 2"
if (b.identityEquals(a)) return "fail 3"
if (a.identityEquals(b)) return "fail 4"
if( a !=b ) return "fail5"
return "OK"
}
@@ -1,21 +0,0 @@
abstract class ClassValAbstract {
abstract var a: Int
class object {
val methods = (this as java.lang.Object).getClass()?.getClassLoader()?.loadClass("ClassValAbstract")?.getMethods()!!
}
}
fun box() : String {
for(m in ClassValAbstract.methods) {
if (m!!.getName() == "getA") {
if(m!!.getModifiers() != 1025)
return "get failed"
}
if (m!!.getName() == "setA") {
if(m!!.getModifiers() != 1025)
return "set failed"
}
}
return "OK"
}
@@ -1,6 +0,0 @@
fun test( n : Number ) = n.toInt().toLong() + n.toLong()
fun box() : String {
val n : Number = 10
return if(test(n) == 20.toLong()) "OK" else "fail"
}
@@ -1,20 +0,0 @@
class Works() : jet.Function0<Object>() {
public override fun invoke():Object {
return "Works" as Object
}
}
class Broken() : jet.Function0<String>() {
public override fun invoke():String {
return "Broken"
}
}
fun box(): String {
val works1: ()->Object = Works();
works1()
val broken1: ()->String = Broken();
broken1()
return "OK"
}
@@ -1,23 +0,0 @@
import java.util.HashMap
data class Pair<First, Second>(val first: First, val second: Second)
fun parseCatalogs(hashMap: Any?) {
val r = toHasMap(hashMap)
if (!r.first) {
return
}
val nodes = r.second
}
fun toHasMap(value: Any?): Pair<Boolean, HashMap<String, Any?>?> {
if(value is HashMap<*, *>) {
return Pair(true, value as HashMap<String, Any?>)
}
return Pair(false, null as HashMap<String, Any?>?)
}
fun box() : String {
parseCatalogs(null)
return "OK"
}
@@ -1,23 +0,0 @@
//KT-1572 Frontend doesn't mark all vars included in closure as refs.
class A(val t : Int) {}
fun testKt1572() : Boolean {
var a = A(0)
var b = A(3)
val changer = {a = b}
b = A(10) // this change has no effect on changer
changer()
return (a.t == 10)
}
fun testPrimitives() : Boolean {
var a = 0
var b = 3
val changer = {a = b}
b = 10
changer()
return (a == 10)
}
fun box() = if (testKt1572() && testPrimitives()) "OK" else "fail"
@@ -1,9 +0,0 @@
fun box() : String {
var i = 0
{
i++
}()
i++ //the problem is here
// i = i + 1 //this way it works
return if (i == 2) "OK" else "fail"
}
@@ -1,8 +0,0 @@
abstract class Foo<T> {
fun hello(id: T) = "O$id"
}
class Bar: Foo<String>() {
}
fun box() = Bar().hello("K")
@@ -1,11 +0,0 @@
fun box(): String {
return Foo().doBar("OK")
}
class Foo() {
val bar : (str : String) -> String = { it }
fun doBar(str : String): String {
return bar(str);
}
}
@@ -1,4 +0,0 @@
fun box(): String {
!true
return "OK"
}
@@ -1,18 +0,0 @@
trait A {
val method : (() -> Unit)?
}
fun test(a : A) {
if (a.method != null) {
a.method!!()
}
}
class B : A {
override val method = { }
}
fun box(): String {
test(B())
return "OK"
}
@@ -1,18 +0,0 @@
trait A {
val method : () -> Unit?
}
fun test(a : A) {
if (a.method != null) {
a.method!!()
}
}
class B : A {
override val method = { }
}
fun box(): String {
test(B())
return "OK"
}
@@ -1,10 +0,0 @@
fun box(): String {
var s = ""
try {
throw RuntimeException()
} catch (e : RuntimeException) {
} finally {
s += "OK"
}
return s
}
@@ -1,23 +0,0 @@
trait A {
val method : (() -> Unit )?
val test : Integer
}
class AImpl : A {
override val method : (() -> Unit )? = {
}
override val test : Integer = Integer(777)
}
fun test(a : A) {
val method = a.method
if (method != null) {
method()
}
}
public fun box() : String {
AImpl().test
test(AImpl())
return "OK"
}
@@ -1,12 +0,0 @@
trait A {
val v: Int
}
class AImpl : A {
override val v: Int = 5
}
public fun box() : String {
(AImpl() : A).v
return "OK"
}
@@ -1,6 +0,0 @@
class T(val f : () -> Any?) {
fun call() : Any? = f()
}
fun box(): String {
return T({ "OK" }).call() as String
}
@@ -1,15 +0,0 @@
class Foo(
var state : Int,
val f : (Int) -> Int){
fun next() : Int {
val nextState = f(state)
state = nextState
return state
}
}
fun box(): String {
val f = Foo(23, {x -> 2 * x})
return if (f.next() == 46) "OK" else "fail"
}
@@ -1,13 +0,0 @@
fun box(): String {
return object {
fun foo(): String {
val f = {}
object : Runnable {
public override fun run() {
f()
}
}
return "OK"
}
}.foo()
}
@@ -1,11 +0,0 @@
public class RunnableFunctionWrapper(val f : () -> Unit) : Runnable {
public override fun run() {
f()
}
}
fun box() : String {
var res = ""
RunnableFunctionWrapper({ res = "OK" }).run()
return res
}
@@ -1,7 +0,0 @@
fun box(): String {
val x = 2
return when(x) {
in (1..3) -> "OK"
else -> "fail"
}
}
@@ -1,11 +0,0 @@
class Greeter(var name : String) {
fun greet() {
name = name.plus("")
System.out?.println("Hello, $name");
}
}
fun box() : String {
Greeter("OK").greet()
return "OK"
}
@@ -1,14 +0,0 @@
class MyList<T>() {
var value: T? = null
fun get(index: Int): T = value!!
fun set(index: Int, value: T) { this.value = value }
}
fun box(): String {
val list = MyList<Int>()
list[17] = 1
list[17] = list[18]++
return "OK"
}
@@ -1,5 +0,0 @@
val Int.ext : () -> Int = { 5 }
val Long.ext : Long = 4.ext().toLong() //(c.kt:4)
val y : Long = 10.toLong().ext
fun box() : String = if (y == 5.toLong()) "OK" else "fail"
@@ -1,5 +0,0 @@
fun box(): String {
if (1 != 0) {
}
return "OK"
}
@@ -1,20 +0,0 @@
class Bar {
}
trait Foo {
fun xyzzy(x: Any?): String
}
fun buildFoo(bar: Bar.() -> Unit): Foo {
return object : Foo {
override fun xyzzy(x: Any?): String {
(x as? Bar)?.bar()
return "OK"
}
}
}
fun box(): String {
val foo = buildFoo({})
return foo.xyzzy(Bar())
}
@@ -1,13 +0,0 @@
trait MyTrait
{
var property : String
fun foo() = property
}
open class B(param : String) : MyTrait
{
override var property : String = param
override fun foo() = super.foo()
}
fun box()= B("OK").foo()
@@ -1,15 +0,0 @@
open class MyClass(param : String) {
var propterty = param
}
trait MyTrait : MyClass
{
fun foo() = propterty
}
open class B(param : String) : MyTrait, MyClass(param)
{
override fun foo() = super<MyTrait>.foo()
}
fun box()= B("OK").foo()
@@ -1,12 +0,0 @@
abstract class Foo<T> {
fun hello(id: T) = "Hi $id"
}
trait Tr {
fun hello(s : String)
}
class Bar: Foo<String>(), Tr {
}
fun box(): String = if (Bar().hello("Reg") == "Hi Reg") "OK" else "Fail"
@@ -1,9 +0,0 @@
fun box(): String {
val sb = StringBuilder()
fun String.plus() {
sb.append(this)
}
+"OK"
return sb.toString()!!
}
@@ -1,14 +0,0 @@
class A {
private val sb: StringBuilder = StringBuilder()
fun String.plus() {
sb.append(this)
}
fun foo(): String {
+"OK"
return sb.toString()!!
}
}
fun box(): String = A().foo()
@@ -1,13 +0,0 @@
open class A<T> {
open fun f(args : Array<T>) {}
}
class B(): A<String>() {
override fun f(args : Array<String>) {}
}
fun main(args: Array<String>) {
B()
}
fun box(): String = "OK"
@@ -1,8 +0,0 @@
class A {
public val f : ()->String = {"OK"}
}
fun box(): String {
val a = A()
return a.f() // does not work: (in runtime) ClassCastException: A cannot be cast to jet.Function0
}
@@ -1,10 +0,0 @@
fun aa(vararg a : String): String = a[0]
fun box(): String {
var result: String = ""
var i = 1
while (3 > i++) {
result = aa(if (true) "OK" else "fail")
}
return result
}
@@ -1,29 +0,0 @@
import java.util.*
public inline fun Int.times(body : () -> Unit) {
var count = this;
while (count > 0) {
body()
count--
}
}
fun calc() : Int {
val a = ArrayList<()->Int>()
2.times {
var j = 1
a.add({ j })
++j
}
var sum = 0
for (f in a) {
val g = f as () -> Int
sum += g()
}
return sum
}
fun box() : String {
val x = calc()
return if (x == 4) "OK" else x.toString()
}
@@ -1,5 +0,0 @@
fun box(): String {
val a = if(true) {
}
return if (a.toString() == "Unit.VALUE") "OK" else "fail"
}
@@ -1,9 +0,0 @@
class Foo {
fun isOk() = true
}
fun box(): String {
val foo: Foo? = Foo()
if (foo?.isOk()!!) return "OK"
return "fail"
}
@@ -1,11 +0,0 @@
fun foo(): String {
return if (true) {
var x = "OK"
fun foo() { x += "fail" }
x
} else "fail"
}
fun box(): String {
return foo()
}
@@ -1,44 +0,0 @@
trait A {
fun foo(): Int
}
class B1 : A {
override fun foo() = 10
}
class B2(val z: Int) : A {
override fun foo() = z
}
fun f1(b: B1): Int {
val o = object : A by b { }
return o.foo()
}
fun f2(b: B2): Int {
val o = object : A by B2(b.z) { }
return o.foo()
}
fun f3(b: B2, mult: Int): Int {
val o = object : A by B2(mult * b.z) { }
return o.foo()
}
fun f4(b: B1, x: Int, y: Int, z: Int): Int {
val o = object : A by b {
fun bar() = x + y + z
}
return o.foo()
}
fun box(): String {
if (f1(B1()) != 10) return "fail #1"
if (f2(B2(239)) != 239) return "fail #2"
if (f3(B2(239), 2) != 239*2) return "fail #3"
if (f4(B1(), 1, 2, 3) != 10) return "fail #4"
return "OK"
}
@@ -1,39 +0,0 @@
class A(var b: Byte) {
fun c(d: Short) = (b + d.toByte()).toChar()
}
fun box() : String {
if(A(10.toByte()).c(20.toShort()) != 30.toByte().toChar()) return "plus failed"
var x = 20.toByte()
var y = 20.toByte()
val foo = {
x++
++x
}
if(++x != 21.toByte() || x++ != 21.toByte() || foo() != 24.toByte() || x != 24.toByte()) return "shared byte fail"
if(++y != 21.toByte() || y++ != 21.toByte() || y != 22.toByte()) return "byte fail"
var xs = 20.toShort()
var ys = 20.toShort()
val foos = {
xs++
++xs
}
if(++xs != 21.toShort() || xs++ != 21.toShort() || foos() != 24.toShort() || xs != 24.toShort()) return "shared short fail"
if(++ys != 21.toShort() || ys++ != 21.toShort() || ys != 22.toShort()) return "short fail"
var xc = 20.toChar()
var yc = 20.toChar()
val fooc = {
xc++
++xc
}
if(++xc != 21.toChar() || xc++ != 21.toChar() || fooc() != 24.toChar() || xc != 24.toChar()) return "shared char fail"
if(++yc != 21.toChar() || yc++ != 21.toChar() || yc != 22.toChar()) return "char fail"
return "OK"
}
@@ -1,10 +0,0 @@
fun main(args: Array<String>) {
try {
} finally {
try {
} catch (e: Throwable) {
}
}
}
fun box() = "OK"
@@ -1,9 +0,0 @@
trait Flusher {
fun flush() = "OK"
}
fun myFlusher() = object : Flusher { }
fun flushIt(flusher: Flusher) = flusher.flush()
fun box() = flushIt(myFlusher())
@@ -1,13 +0,0 @@
fun box() : String {
230?.toByte()?.hashCode()
9.hashCode()
if(230.equals(9.toByte())) {
return "fail"
}
if(230 == 9.toByte().toInt()) {
return "fail"
}
return "OK"
}
@@ -1,6 +0,0 @@
class A(
val i : Int,
val j : Int = i
)
fun box() = if (A(1).j == 1) "OK" else "fail"
@@ -1,3 +0,0 @@
fun foo(i: Int, j: Int = i) = j
fun box() = if (foo(1) == 1) "OK" else "fail"
@@ -1,5 +0,0 @@
fun box(): String {
(0.toLong() as Number?)?.toByte()
(0 as Int?)?.toDouble()
return "OK"
}
@@ -1,7 +0,0 @@
fun box(): String {
fun rmrf(i: Int) {
if (i > 0) rmrf(i - 1)
}
rmrf(5)
return "OK"
}
@@ -1,8 +0,0 @@
public open class Test(): java.util.RandomAccess, Cloneable, java.io.Serializable
{
public override fun clone(): Test = Test() // Override 'clone()' with more precise type 'Test'
public override fun toString() = "OK"
}
fun box() = Test().clone().toString()
@@ -1,6 +0,0 @@
fun box(): String {
1 in 1.rangeTo(10)
1..10
'h' in 'A'.rangeTo('Z')
return "OK"
}
@@ -1,10 +0,0 @@
class A() {
fun foo() {
System.out?.println(1)
}
}
fun box() : String {
val a : A = A()
return "OK"
}
@@ -1,14 +0,0 @@
class P {
var x : Int = 0
private set
fun foo() {
({ x = 4 })()
}
}
fun box() : String {
val p = P()
p.foo()
return if (p.x == 4) "OK" else "fail"
}
@@ -1,7 +0,0 @@
enum class A(val b: String) {
E1: A("OK"){ override fun t() = b }
abstract fun t(): String
}
fun box()= A.E1.t()
@@ -1,41 +0,0 @@
fun main(args: Array<String>?) {
val y: Unit = Unit.VALUE //do not compile
A<Unit>() //do not compile
C<Unit>(Unit.VALUE) //do not compile
//do not compile
System.out?.println(fff<Unit>(Unit.VALUE)) //do not compile
System.out?.println(id<Unit>(y)) //do not compile
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(Array<Int>(0,{0}),{(e : Int) : Unit -> }))) //do not compile
}
class A<T>()
class C<T>(val value: T) {
fun foo(): T = value
}
fun <T> fff(x: T) : T { return x }
fun <T> id(value: T): T = value
fun foreach(array: Array<Int>, action: (Int)-> Unit) {
for (el in array) {
action(el) //exception through compilation (see below)
}
}
fun almostFilter(array: Array<Int>, action: (Int)-> Int) {
for (el in array) {
action(el)
}
}
fun box() : String {
val a = Array<Int> (3,{-1})
a[0] = 0
a[1] = 1
a[2] = 2
foreach(a, { (el : Int) : Unit -> System.out?.println(el) })
almostFilter(a, { (el : Int) : Int -> el })
main(null)
return "OK"
}
@@ -1,58 +0,0 @@
fun t1 () {
val a1 = arrayOfNulls<String>(1)
a1[0] = "0" //ok
val s = a1[0] //ok
}
fun t2 () {
val a2 = Array<Int>(1,{0})
a2[0] = 0 //ok
var i = a2[0] //ok
}
fun t3 () {
val a3 = arrayOfNulls<Int>(1)
a3[0] = 0 //verify error
var j = a3[0] //ok
var k : Int = a3[0] ?: 5 //ok
}
fun t4 () {
val b1 = StrangeIntArray(10)
b1[4] = 5 //ok
var i = b1[1] //ok
}
fun t5 () {
val b2 = StrangeArray<Int>(10, 0)
b2.set(4, 5) //ok
b2[4] = 5 //verify error
var i = b2.get(2) //ok
i = b2[1] //verify error
}
fun t6() {
val b3 = StrangeArray<Int?>(10, 0)
b3.set(5, 6) //ok
b3[4] = 5 //verify error
val v = b3[1] //ok
}
fun box() : String {
return "OK"
}
class StrangeArray<T>(size: Int, private var defaultValue: T) {
fun get(index: Int): T = defaultValue
fun set(index: Int, v: T) {
defaultValue = v
}
}
class StrangeIntArray(size: Int) {
private var defaultValue = 0
fun get(index: Int): Int = defaultValue
fun set(index: Int, v: Int) {
defaultValue = v
}
}
@@ -1,15 +0,0 @@
class A {
class object {
val b = 0
val c = b
{
val d = b
}
}
}
fun box(): String {
A()
return if (A.c == A.b) "OK" else "Fail"
}
@@ -1,5 +0,0 @@
fun box() : String {
val i : Int? = 0
val j = i?.plus(3) //verify error
return "OK"
}
@@ -1,35 +0,0 @@
class JsonObject() {
}
class JsonArray() {
}
public trait Formatter<in IN: Any, out OUT: Any> {
public fun format(source: IN?): OUT
}
public trait MultiFormatter <in IN: Any, out OUT: Any> {
public fun format(source: Collection<IN>): OUT
}
public class Project() {
}
public trait JsonFormatter<in IN: Any>: Formatter<IN, JsonObject>, MultiFormatter<IN, JsonArray> {
public override fun format(source: Collection<IN>): JsonArray {
return JsonArray();
}
}
public class ProjectJsonFormatter(): JsonFormatter<Project> {
public override fun format(source: Project?): JsonObject {
return JsonObject()
}
}
fun box(): String {
val formatter = ProjectJsonFormatter()
return if (formatter.format(Project()) != null) "OK" else "fail"
}
@@ -1,19 +0,0 @@
public trait LoggerAware {
public val logger: StringBuilder
}
public abstract class HttpServer(): LoggerAware {
public fun start() {
logger.append("OK")
}
}
public class MyHttpServer(): HttpServer() {
public override val logger = StringBuilder()
}
fun box(): String {
val server = MyHttpServer()
server.start()
return server.logger.toString()!!
}
@@ -1,11 +0,0 @@
import java.util.AbstractList
class MyList(): AbstractList<String>() {
public fun getModificationCount(): Int = modCount
public override fun get(index: Int): String = ""
public override fun size(): Int = 0
}
fun box(): String {
return if (MyList().getModificationCount() == 0) "OK" else "fail"
}
@@ -1,18 +0,0 @@
class C {
public object Obj {
val o = "O"
object InnerObj {
fun k() = "K"
}
class D {
val ko = "KO"
}
}
}
fun box(): String {
val res = C().Obj.o + C().Obj.InnerObj.k() + C().Obj.D().ko
return if (res == "OKKO") "OK" else "Fail: $res"
}
@@ -1,42 +0,0 @@
import java.util.ArrayList
class JsonObject {
}
class JsonArray {
}
class ProjectInfo {
public fun toString(): String = "OK"
}
public trait Parser<in IN: Any, out OUT: Any> {
public fun parse(source: IN): OUT
}
public trait MultiParser<in IN: Any, out OUT: Any> {
public fun parse(source: IN): Collection<OUT>
}
public trait JsonParser<T: Any>: Parser<JsonObject, T>, MultiParser<JsonArray, T> {
public override fun parse(source: JsonArray): Collection<T> {
return ArrayList<T>()
}
}
public abstract class ProjectInfoJsonParser(): JsonParser<ProjectInfo> {
public override fun parse(source: JsonObject): ProjectInfo {
return ProjectInfo()
}
}
class ProjectApiContext {
public val projectInfoJsonParser: ProjectInfoJsonParser = object : ProjectInfoJsonParser(){
}
}
fun box(): String {
val context = ProjectApiContext()
val array = context.projectInfoJsonParser.parse(JsonArray())
return if (array != null) "OK" else "fail"
}
@@ -1,15 +0,0 @@
fun box(): String {
9 in 0..9
val intRange = 0..9
9 in intRange
val charRange = '0'..'9'
'9' in charRange
val byteRange = 0.toByte()..9.toByte()
9.toByte() in byteRange
val longRange = 0.toLong()..9.toLong()
9.toLong() in longRange
val shortRange = 0.toShort()..9.toShort()
9.toShort() in shortRange
return "OK"
}
@@ -1,25 +0,0 @@
import java.util.HashSet
fun box() : String{
val set = HashSet<String>()
set.add("foo")
val t1 = "foo" in set // returns true, valid
if(!t1) return "fail1"
val t2 = "foo" !in set // returns true, invalid
if(t2) return "fail2"
val t3 = "bar" in set // returns false, valid
if(t3) return "fail3"
val t4 = "bar" !in set // return false, invalid
if(!t4) return "fail4"
val t5 = when("foo") {
in set -> true
else -> false
}
if(!t5) return "fail5"
val t6 = when("foo") {
!in set -> true
else -> false
}
if(t6) return "fail6"
return "OK"
}
@@ -1,19 +0,0 @@
fun box() : String {
val i: Int? = 7
val j: Int? = null
val k = 7
//verify errors
if (i == 7) {}
if (7 == i) {}
if (j == 7) {}
if (7 == j) {}
if (i == k) {}
if (k == i) {}
if (j == k) {}
if (k == j) {}
return "OK"
}
@@ -1,8 +0,0 @@
fun box() : String {
val t = java.lang.String.copyValueOf(java.lang.String("s").toCharArray())
val i = java.lang.Integer.MAX_VALUE
val j = java.lang.Integer.valueOf(15)
val s = java.lang.String.valueOf(1)
val l = java.util.Collections.emptyList<Int>()
return "OK"
}
@@ -1,32 +0,0 @@
fun foo() {
val l = java.util.ArrayList<Int>(2)
l.add(1)
for (el in l) {}
//verify error "Expecting to find integer on stack"
val iterator = l.iterator()
//another verify error "Mismatched stack types"
while (iterator?.hasNext() ?: false) {
val i = iterator?.next()
}
//the same
if (iterator != null) {
while (iterator.hasNext()) {
val i = iterator?.next()
}
}
//this way it works
if (iterator != null) {
while (iterator.hasNext()) {
iterator.next() //because of the bug KT-244 i can't write "val i = iterator.next()"
}
}
}
fun box() : String {
return "OK"
}
@@ -1,8 +0,0 @@
fun foo(i: Int) : Int =
when (i) {
1 -> 1
null -> 1
else -> 1
}
fun box() : String = if (foo(1) == 1) "OK" else "fail"
@@ -1,38 +0,0 @@
fun t1() : Boolean {
val s1 : String? = "sff"
val s2 : String? = null
return s1?.length == 3 && s2?.length == null
}
fun t2() : Boolean {
val c1: C? = C(1)
val c2: C? = null
return c1?.x == 1 && c2?.x == null
}
fun t3() {
val d: D = D("s")
val x = d?.s
if (!(d?.s == "s")) throw AssertionError()
}
fun t4() {
val e: E? = E()
if (!(e?.bar() == e)) throw AssertionError()
val x = e?.foo()
}
fun box() : String {
if(!t1 ()) return "fail"
if(!t2 ()) return "fail"
t3()
t4()
return "OK"
}
class C(val x: Int)
class D(val s: String)
class E() {
fun foo() = 1
fun bar() = this
}
@@ -1,22 +0,0 @@
package test
trait A {
public val c: String
get() = "OK"
}
trait B {
protected val c: String
}
open class C {
private val c: String = "FAIL"
}
open class D: C(), A, B {
val b = c
}
fun box() : String {
return D().c
}
@@ -1,7 +0,0 @@
fun box() : String {
val b = true as? Boolean //exception
val i = 1 as Int //exception
val j = 1 as Int? //ok
val s = "s" as String //ok
return "OK"
}
@@ -1,13 +0,0 @@
fun box() = Class().printSome()
public abstract class AbstractClass<T> {
public fun printSome() : T = some
public abstract val some: T
}
public class Class: AbstractClass<String>() {
public override val some: String
get() = "OK"
}
@@ -1,14 +0,0 @@
fun box() =
B().method()
public open class A(){
public open fun method() : String = "OK"
}
public class B(): A(){
public override fun method() : String {
return ({
super.method()
})()
}
}

Some files were not shown because too many files have changed in this diff Show More