TEST:objects and companion objects.
This commit is contained in:
committed by
vvlevchenko
parent
618bf4cb80
commit
8892986be3
@@ -663,3 +663,18 @@ task main_exception(type: RunKonanTest) {
|
|||||||
source = "runtime/basic/main_exception.kt"
|
source = "runtime/basic/main_exception.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
task initializers0(type: RunKonanTest) {
|
||||||
|
goldValue = "main\n" +
|
||||||
|
"B::constructor(1)\n" +
|
||||||
|
"A::companion\n" +
|
||||||
|
"A::companion::foo\n" +
|
||||||
|
"A::companion::foo\n" +
|
||||||
|
"B::constructor(0)\n" +
|
||||||
|
"B::constructor()\n" +
|
||||||
|
"A::Obj\n" +
|
||||||
|
"A::AObj::foo\n" +
|
||||||
|
"A::AObj::foo\n"
|
||||||
|
source = "runtime/basic/initializers0.kt"
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
class A {
|
||||||
|
init{
|
||||||
|
println ("A::init")
|
||||||
|
}
|
||||||
|
|
||||||
|
val a = 1
|
||||||
|
|
||||||
|
companion object :B(1) {
|
||||||
|
init {
|
||||||
|
println ("A::companion")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
println("A::companion::foo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object AObj : B(){
|
||||||
|
init {
|
||||||
|
println("A::Obj")
|
||||||
|
}
|
||||||
|
fun foo() {
|
||||||
|
println("A::AObj::foo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main(args:Array<String>) {
|
||||||
|
println("main")
|
||||||
|
A.foo()
|
||||||
|
A.foo()
|
||||||
|
A.AObj.foo()
|
||||||
|
A.AObj.foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class B(val a:Int, val b:Int) {
|
||||||
|
constructor(a:Int):this (a, 0) {
|
||||||
|
println("B::constructor(" + a.toString()+ ")")
|
||||||
|
}
|
||||||
|
constructor():this(0) {
|
||||||
|
println("B::constructor()")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user