blob: dbeb993a5820c3393ae0e0d4862e4ee2afc3cda7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
trait A
{
print("-A")
def delayedInit(body: => Unit) = {
body
postConstructionCode
}
def postConstructionCode: Unit = {
print("\n A+")
}
}
trait B extends A {
print(" -B")
override def postConstructionCode: Unit = {
super.postConstructionCode
print(" B+")
}
}
trait C extends B {
print(" -C")
override def postConstructionCode: Unit = {
super.postConstructionCode
print(" C+")
}
}
class D() extends C {
print(" -D")
override def postConstructionCode: Unit = {
super.postConstructionCode
print(" D+")
}
}
class E() extends D() {
print(" -E")
override def postConstructionCode: Unit = {
super.postConstructionCode
print(" E+")
}
}
object Test {
def p(msg: String) = println("\n\n// " + msg)
def main(args: Array[String]): Unit = {
val f: A => Unit = _.postConstructionCode
p("new C { }")
f(new C { })
p("new C { 5 }")
f(new C { 5 })
p("new D()")
f(new D())
p("new D() { }")
f(new D() { })
p("new D() { val x = 5 }")
f(new D() { val x = 5 })
p("new { val x = 5 } with D()")
f(new D() {
// TODO NEEDS MANUAL CHANGE (early initializers)
// BEGIN copied early initializers
val x = 5
// END copied early initializers
})
p("new E() { val x = 5 }")
f(new E() { val x = 5 })
p("new { val x = 5 } with E()")
f(new E() {
// TODO NEEDS MANUAL CHANGE (early initializers)
// BEGIN copied early initializers
val x = 5
// END copied early initializers
})
p("new { val x = 5 } with E() { }")
f(new E() {
// TODO NEEDS MANUAL CHANGE (early initializers)
// BEGIN copied early initializers
val x = 5
// END copied early initializers
})
p("new { val x = 5 } with E() { 5 }")
f(new E() {
// TODO NEEDS MANUAL CHANGE (early initializers)
// BEGIN copied early initializers
val x = 5
// END copied early initializers
5 })
println("")
}
}
|