KT-1361: "this" is not treated correctly when object is created.

This commit is contained in:
pTalanov
2012-03-13 14:30:26 +04:00
parent 50a42a2f07
commit 15437cbbf6
5 changed files with 113 additions and 5 deletions
@@ -0,0 +1,21 @@
//This is not treated correctly when object is created.
package foo
class B {
val d = true
fun f() : Boolean {
val c = object {
fun foo() : Boolean {
return d
}
}
return c.foo()
}
}
fun box() : Boolean {
return B().f()
}
@@ -0,0 +1,52 @@
package foo
class Data(val rawData : Array<Int>, val width : Int, val height : Int) {
fun get(x : Int, y : Int) : ColorLike {
return object : ColorLike {
override val red: Int = rawData[(y * width + x) * 4 + 0];
override val green: Int = rawData[(y * width + x) * 4 + 1];
override val blue: Int = rawData[(y * width + x) * 4 + 2];
}
}
fun set(x : Int, y : Int, color : ColorLike) {
rawData[(y * width + x) * 4 + 0] = color.red;
rawData[(y * width + x) * 4 + 1] = color.green;
rawData[(y * width + x) * 4 + 2] = color.blue;
}
fun each(block : (x : Int, y : Int)->Unit) {
for (x in 0..width - 1) {
for (y in 0..height - 1) {
block(x, y)
}
}
}
}
class Color(r : Int, g : Int, b : Int) : ColorLike {
override val red: Int = r
override val green: Int = g
override val blue: Int = b
}
trait ColorLike {
val red : Int;
val green : Int;
val blue : Int;
}
fun box() : Boolean {
val d = Data(Array(4) {0}, 1, 1)
if (d[0, 0].red != 0) {
return false
}
if (d[0, 0].green != 0) {
return false
}
if (d[0, 0].blue != 0) {
return false
}
return true
}