Merge remote branch 'origin'

This commit is contained in:
Dmitry Jemerov
2011-10-01 10:55:18 +02:00
901 changed files with 26211 additions and 9704 deletions
+15
View File
@@ -0,0 +1,15 @@
import java.lang.Integer
open class C {
open fun f(): Any = "C f"
}
class D() : C {
override fun f(): String = "D f"
}
fun box(): String{
val d : C = D()
if(d.f() != "D f") return "fail f"
return "OK"
}
@@ -2,7 +2,7 @@ class C() {
fun getInstance(): Runnable = C
class object: Runnable {
fun run(): Unit { }
override fun run(): Unit { }
}
}
@@ -1,5 +1,5 @@
abstract open class Default {
fun defaultValue(): Int
abstract fun defaultValue(): Int
}
class MyInt() {
@@ -1,11 +1,13 @@
class Base() {
public var v : Int
// Changed when traits were introduced. May not make sense any more
open class Base() {
public var v : Int = 0
}
class Left() : Base() {}
class Right() : Base() {}
open class Left() : Base() {}
trait Right : Base {}
class D() : Left(), Right()
class D() : Left(), Right
fun vl(l : Left) : Int = l.v
fun vr(r : Right) : Int = r.v
@@ -1,8 +1,8 @@
class Base() {
open class Base() {
fun n(n : Int) : Int = n + 1
}
class Abstract {}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
+14 -6
View File
@@ -1,9 +1,17 @@
class X(val x : Int) {}
class Y(val y : Int) {}
// Changed when traits were introduced. May not make sense any more
class Point(x : Int, y : Int) : X(x) , Y(y) {}
open class X(val x : Int) {}
trait Y {
abstract val y : Int
}
class Abstract {}
class YImpl(override val y : Int) : Y {}
class Point(x : Int, yy : Int) : X(x) , Y {
override val y : Int = yy
}
trait Abstract {}
class P1(x : Int, yy : Y) : Abstract, X(x), Y by yy {}
class P2(x : Int, yy : Y) : X(x), Abstract, Y by yy {}
@@ -12,12 +20,12 @@ class P4(x : Int, yy : Y) : Y by yy, Abstract, X(x) {}
fun box() : String {
if (X(239).x != 239) return "FAIL #1"
if (Y(239).y != 239) return "FAIL #2"
if (YImpl(239).y != 239) return "FAIL #2"
val p = Point(240, -1)
if (p.x + p.y != 239) return "FAIL #3"
val y = Y(-1)
val y = YImpl(-1)
val p1 = P1(240, y)
if (p1.x + p1.y != 239) return "FAIL #4"
val p2 = P2(240, y)
@@ -1,5 +1,5 @@
class Outer() {
class InnerBase() {
open class InnerBase() {
}
class InnerDerived(): InnerBase() {
@@ -1,4 +1,4 @@
class Foo {
open class Foo {
fun xyzzy(): String = "xyzzy"
}
@@ -2,7 +2,7 @@ class C() {
public var f: Int
{
f = 610
$f = 610
}
}
@@ -1,16 +1,16 @@
class Base() {
open class Base() {
public val plain = 239
public val read : Int
get() = 239
public var readwrite : Int
public var readwrite : Int = 0
get() = $readwrite + 1
set(n : Int) {
$readwrite = n
}
}
class Abstract {}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
@@ -1,7 +1,7 @@
class Outer() {
public val s = "xyzzy"
class InnerBase(public val name: String) {
open class InnerBase(public val name: String) {
}
class InnerDerived(): InnerBase(s) {
@@ -1,9 +1,11 @@
class Left() {}
class Right() {
virtual fun f() = 42
// Changed when traits were introduced. May not make sense any more
trait Left {}
open class Right() {
open fun f() = 42
}
class D() : Left(), Right() {
class D() : Left, Right() {
override fun f() = 239
}
@@ -0,0 +1,14 @@
fun box() : String {
val a = Array<Int> (5, {0})
var i = 0
var sum = 0
for(el in 0..4) {
a[i] = i++
}
for (el in a) {
sum = sum + el
}
if(sum != 10) return "a failed"
return "OK"
}
@@ -0,0 +1,16 @@
fun box() : String {
val b : Array<Int?> = Array<Int?> (5)
var i = 0
var sum = 0
while(i < 5) {
b[i] = i++
}
sum = 0
for (el in b) {
sum = sum + (el ?: 0)
}
System.out?.println(sum)
if(sum != 10) return "b failed"
return "OK"
}
@@ -0,0 +1,14 @@
fun box() : String {
val a = IntArray (5)
var i = 0
var sum = 0
for(el in 0..4) {
a[i] = i++
}
for (el in a) {
sum = sum + el
}
if(sum != 10) return "a failed"
return "OK"
}
@@ -0,0 +1,115 @@
fun box() : String {
var sum : Int = 0
var i = 0
val c6 = MyCollection4()
sum = 0
for (el in c6) {
sum = sum + el
}
if(sum != 15) return "c6 failed"
val c5 = MyCollection3()
sum = 0
for (el in c5) {
sum = sum + (el ?: 0)
}
if(sum != 15) return "c5 failed"
val c1: java.lang.Iterable<Int> = MyCollection1()
sum = 0
for (el in c1) {
sum = sum + el
}
if(sum != 15) return "c1 failed"
val c2 = MyCollection1()
sum = 0
for (el in c2) {
sum = sum + el
}
if(sum != 15) return "c2 failed"
val c3: Iterable<Int> = MyCollection2()
sum = 0
for (el in c3) {
sum = sum + el
}
if(sum != 15) return "c3 failed"
val c4 = MyCollection2()
sum = 0
for (el in c4) {
sum = sum + el
}
if(sum != 15) return "c4 failed"
val a : Array<Int> = Array<Int> (5, {0})
for(el in 0..4) {
a[i] = i++
}
sum = 0
for (el in a) {
sum = sum + el
}
if(sum != 10) return "a failed"
val b : Array<Int?> = Array<Int?> (5)
i = 0
while(i < 5) {
b[i] = i++
}
sum = 0
for (el in b) {
sum = sum + (el ?: 0)
}
System.out?.println(sum)
if(sum != 10) return "b failed"
return "OK"
}
class MyCollection1(): java.lang.Iterable<Int> {
override fun iterator(): java.util.Iterator<Int> = MyIterator()
class MyIterator(): java.util.Iterator<Int> {
var k : Int = 5
override fun next() : Int = k--
override fun hasNext() = k > 0
override fun remove() {}
}
}
class MyCollection2(): Iterable<Int> {
override fun iterator(): Iterator<Int> = MyIterator()
class MyIterator(): Iterator<Int> {
var k : Int = 5
override fun next() : Int = k--
override fun hasNext() = k > 0
}
}
class MyCollection3() {
fun iterator() = MyIterator()
class MyIterator() {
var k : Int = 5
fun next() : Int? = k--
fun hasNext() = k > 0
}
}
class MyCollection4() {
fun iterator() = MyIterator()
class MyIterator() {
var k : Int = 5
fun next() : Int = k--
fun hasNext() = k > 0
}
}
@@ -0,0 +1,9 @@
fun isDigit(a: Int) : String {
val aa = java.util.ArrayList<Int> ()
aa.add(239)
if(a in aa) return "array list"
if(a in 0..9) return "digit"
if(a !in 0..100) return "not small"
return "something"
}
@@ -0,0 +1,11 @@
fun typeName(a: Any?) : String {
return when(a) {
is java.util.ArrayList<Int> => "array list"
else => "no idea"
}
}
fun box() : String {
if(typeName(java.util.ArrayList<Int> ()) != "array list") return "array list failed"
return "OK"
}
@@ -1,4 +1,11 @@
fun isDigit(a: Int) = when(a) {
in 0..9 => "digit"
else => "something"
fun isDigit(a: Int) : String {
val aa = java.util.ArrayList<Int> ()
aa.add(239)
return when(a) {
in aa => "array list"
in 0..9 => "digit"
!in 0..100 => "not small"
else => "something"
}
}
@@ -0,0 +1,10 @@
class A() {
fun foo() {
System.out?.println(1)
}
}
fun box() : String {
val a : A = A()
return "OK"
}
@@ -0,0 +1,41 @@
fun main(args: Array<String>?) {
val y: Unit = () //do not compile
A<Unit>() //do not compile
C<Unit>(()) //do not compile
//do not compile
System.out?.println(fff<Unit>(())) //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: fun(Int): Unit) {
for (el in array) {
action(el) //exception through compilation (see below)
}
}
fun almostFilter(array: Array<Int>, action: fun(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"
}
@@ -0,0 +1,58 @@
fun t1 () {
val a1 = Array<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 = Array<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
}
}
@@ -0,0 +1,3 @@
fun box(i: Int?) {
val j = i?.plus(3) //verify error
}
@@ -0,0 +1,19 @@
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"
}
@@ -0,0 +1,8 @@
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"
}
@@ -0,0 +1,32 @@
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"
}
@@ -0,0 +1,38 @@
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")
System.out?.println(d?.s)
System.out?.println(d?.s == "s") //prints true
System.out?.println(d) //ok
}
fun t4() {
val e: E? = E()
System.out?.println(e?.foo() == e) //verify error
System.out?.println(e?.foo()) //verify error
}
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
}
@@ -0,0 +1,7 @@
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"
}
@@ -0,0 +1,35 @@
namespace x
class Outer(val name: String) {
class Inner() {
val me = name
class object {
fun bar() = "bar"
}
}
class object {
class StaticInner() {
class object {
fun f() = "oo"
}
}
}
}
fun box (): String {
val inner = Outer("mama").Inner() //verify error
if(inner.me != "mama")
return "fail"
val outer = Outer ("papa")
val inner2 = outer.Inner ()
if(inner2.me != "papa")
return "fail"
if(Outer.StaticInner.f() != "oo" )
return "fail"
return "OK"
}
@@ -0,0 +1,20 @@
class A<T>(var t: T) {}
class B<R>(val r: R) {}
fun box() : String {
val ai = A<Int>(1)
val aai = A<A<Int>>(ai)
if(aai.t.t != 1) return "fail"
/*
aai.t.t = 2
if(aai.t.t != 2) return "fail"
if(ai.t != 2) return "fail"
if(aai.t != ai) return "fail"
if(aai.t !== ai) return "fail"
val abi = A<B<Int>>(B<Int>(1))
if(abi.t.r != 1) return "fail"
*/
return "OK"
}
+251
View File
@@ -0,0 +1,251 @@
class A() {}
open class B<T>() {
fun isT (a : Any?) : Boolean {
return a is T
}
}
class C() : B<String>() {
}
class D<T>() : B<B<T>>() {
}
fun t1() : Boolean {
val a = A()
if(a !is A) return false
return true
}
fun t2() : Boolean {
val a = A()
if(a !is A?) return false
return true
}
fun t3() : Boolean {
val a = A()
if(null !is A?) return false
return true
}
fun t4 () : Boolean {
val b = B<String>()
if(b !is B<String>) return false
return true
}
fun t5 () : Boolean {
val b = B<String>()
if(b !is B<String>?) return false
return true
}
fun t6 () : Boolean {
if(null !is B<String>?) return false
return true
}
fun t7 () : Boolean {
val b = B<String>()
if(!b.isT("aaa")) return false
return true
}
fun t8 () : Boolean {
val b = B<String>()
if(b.isT(10)) return false
return true
}
fun t9 () : Boolean {
val b = B<String>()
if(b.isT(null)) return false
return true
}
fun t10 () : Boolean {
val d = B<String?>()
if(!d.isT("aaa")) return false
return true
}
fun t11 () : Boolean {
val d = B<String?>()
if(d.isT(10)) return false
return true
}
fun t12 () : Boolean {
val d = B<String?>()
if(!d.isT(null)) return false
return true
}
fun t13 () : Boolean {
val f = B<java.lang.String?>()
if(!f.isT("aaa")) return false
return true
}
fun t14 () : Boolean {
val f = B<java.lang.String?>()
if(f.isT(10)) return false
return true
}
fun t15 () : Boolean {
val f = B<java.lang.String?>()
if(!f.isT(null)) return false
return true
}
fun t16 () : Boolean {
val c = B<Int>()
if(c.isT("aaa")) return false
return true
}
fun t17 () : Boolean {
val c = B<Int>()
if(!c.isT(10)) return false
return true
}
fun t18 () : Boolean {
val c = B<Int>()
if(c.isT(null)) return false
return true
}
fun t19 () : Boolean {
val e = B<Int?>()
if(e.isT("aaa")) return false
return true
}
fun t20 () : Boolean {
val e = B<Int?>()
if(!e.isT(10)) return false
return true
}
fun t21 () : Boolean {
val e = B<Int?>()
if(!e.isT(null)) return false
return true
}
fun t22 () : Boolean {
val b = B<String>()
val w : B<String>? = b as B<String> //ok
val x = w as B<String>? //TypeCastException
return true
}
fun t23 () : Boolean {
val b = B<String>()
val v = b as B<String> //ok
return true
}
fun t24 () : Boolean {
val b = B<String>()
val u = b as B<String>? //TypeCastException
return true
}
fun t25 () : Boolean {
val c = C()
if(!c.isT("aaa")) return false
return true
}
fun t26 () : Boolean {
val d = D<String>()
if(!d.isT(B<String>())) return false
return true
}
fun box() : String {
/*
if(!t1()) {
return "t1 failed"
}
if(!t2()) {
return "t2 failed"
}
if(!t3()) {
return "t3 failed"
}
if(!t4()) {
return "t4 failed"
}
if(!t5()) {
return "t5 failed"
}
if(!t6()) {
return "t6 failed"
}
if(!t7()) {
return "t7 failed"
}
if(!t8()) {
return "t8 failed"
}
if(!t9()) {
return "t9 failed"
}
if(!t10()) {
return "t10 failed"
}
if(!t11()) {
return "t11 failed"
}
if(!t12()) {
return "t12 failed"
}
if(!t13()) {
return "t13 failed"
}
if(!t14()) {
return "t14 failed"
}
if(!t15()) {
return "t15 failed"
}
if(!t16()) {
return "t16 failed"
}
if(!t17()) {
return "t17 failed"
}
if(!t18()) {
return "t18 failed"
}
if(!t19()) {
return "t19 failed"
}
if(!t20()) {
return "t10 failed"
}
if(!t21()) {
return "t21 failed"
}
if(!t22()) {
return "t22 failed"
}
if(!t23()) {
return "t23 failed"
}
if(!t24()) {
return "t24 failed"
}
if(!t25()) {
return "t25 failed"
}
*/
if(!t26()) {
return "t26 failed"
}
return "OK"
}
@@ -0,0 +1,4 @@
// KT-297 Overload resolution ambiguity with required in trait
trait ALE<T> : java.util.ArrayList<T> {
fun getOrValue(index: Int, value : T) : T = if(index >= 0 && index < size()) get(index) else value
}
@@ -0,0 +1,17 @@
class MyRange1() : Range<Int> {
override fun contains(item: Int) = true
}
class MyRange2() {
fun contains(item: Int) = true
}
fun box(): String {
if (1 in MyRange1()) {
if (1 in MyRange2()) {
return "OK"
}
return "fail 2"
}
return "fail 1"
}
@@ -0,0 +1,49 @@
namespace test
class List<T>(len: Int) {
val a : Array<T> = Array<T>(len)
fun reverse() {
var i = 0
var j = a.size-1
while(i < j) {
val x = a[i]
a[i++] = a[j]
a[j--] = x
}
}
}
fun box() : String {
val d = List<Int>(1)
d.a[0] = 10
println(d.a[0])
val a = List<String>(1)
a.a[0] = "1"
println(a.a[0])
val b = List<Int?>(1)
b.a[0] = 10
println(b.a[0])
val c = List<Array<Int>>(1)
c.a[0] = Array<Int>(4,{-1})
println(c.a[0].size)
val e = List<Int>(5)
e.a[0] = 0
e.a[1] = 1
e.a[2] = 2
e.a[3] = 3
e.a[4] = 4
e.reverse()
for(el in e.a)
println(el)
return "OK"
}
fun println(s : Any?) {
System.out?.println(s);
}
@@ -0,0 +1,29 @@
class A() {
var xi = 0
var xin : Int? = 0
var xinn : Int? = null
var xl = 0.lng
var xln : Long? = 0.lng
var xlnn : Long? = null
var xb = 0.byt
var xbn : Byte? = 0.byt
var xbnn : Byte? = null
var xf = 0.flt
var xfn : Float? = 0.flt
var xfnn : Float? = null
var xd = 0.dbl
var xdn : Double? = 0.dbl
var xdnn : Double? = null
var xs = 0.sht
var xsn : Short? = 0.sht
var xsnn : Short? = null
}
fun box() : String {
return "OK"
}
+21
View File
@@ -0,0 +1,21 @@
trait AL {
fun get(index: Int) : Any? = null
}
trait ALE<T> : AL {
fun getOrNull(index: Int, value: T) : T {
val r = get(index) as? T
return r ?: value
}
}
open class SmartArrayList() : ALE<String> {
}
class SmartArrayList2() : SmartArrayList(), AL {
}
fun box() : String {
val c = SmartArrayList2()
return if("239" == c.getOrNull(0, "239")) "OK" else "fail"
}
+12
View File
@@ -0,0 +1,12 @@
trait SimpleClass : java.lang.Object {
fun foo() : String = "239 " + toString ()
}
class SimpleClassImpl() : SimpleClass {
override fun toString() = "SimpleClassImpl"
}
fun box() : String {
val c = SimpleClassImpl()
return if("239 SimpleClassImpl" == c.foo()) "OK" else "fail"
}
+60
View File
@@ -0,0 +1,60 @@
trait ISized {
val size : Int
}
trait javaUtilIterator<T> : java.util.Iterator<T> {
override fun remove() : Unit {
throw UnsupportedOperationException()
}
}
class MyIterator<T>(val array : ReadOnlyArray<T>) : javaUtilIterator<T> {
private var index = 0
override fun hasNext() : Boolean = index < array.size
override fun next() : T = array.get(index++)
}
trait ReadOnlyArray<out T> : ISized, java.lang.Iterable<T> {
fun get(index : Int) : T
class Default {
fun check(v: Any) = v is T
}
override fun iterator() : java.util.Iterator<T> = MyIterator<T>(this)
}
trait WriteOnlyArray<in T> : ISized {
fun set(index : Int, value : T) : Unit
fun set(from: Int, count: Int, value: T) {
for(i in from..from+count-1) {
set(i, value)
}
}
}
class MutableArray<T>(length: Int) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<T>(length)
override fun get(index : Int) : T = array[index]
override fun set(index : Int, value : T) : Unit { array[index] = value }
override val size : Int
get() = array.size
}
fun box() : String {
var a = MutableArray<Int> (4)
a [0] = 10
a.set(1, 2, 13)
a [3] = 40
System.out?.println(a.iterator())
System.out?.println(a.iterator().hasNext())
for(el in a) {
System.out?.println(el)
}
return "OK"
}
@@ -0,0 +1,15 @@
open class AL<T> {
fun get(index: Int) : T? = null
}
trait ALE<T> : AL<T> {
fun getOrValue(index: Int, value : T) : T = get(index) ?: value
}
class SmartArrayList() : ALE<String>, AL<String> {
}
fun box() : String {
val c = SmartArrayList()
return if("239" == c.getOrValue(0, "239")) "OK" else "fail"
}
+15
View File
@@ -0,0 +1,15 @@
class Box<T>() {
open class Inner () {
fun isT(s : Any) = if(s is T) "OK" else "fail"
}
class Inner2() : Inner() {
}
fun inner() = Inner2()
}
fun box(): String {
return Box<String>.inner().isT("OK")
}