Skip to content

Commit 81efdfa

Browse files
committed
Improve traitNoInit test to actually test if $init$ is present
1 parent e6e81d6 commit 81efdfa

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tests/run/traitNoInit.scala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
trait Foo {
2-
//println("hello")
1+
trait NoInit {
2+
def meth(x: Int): Int
3+
}
4+
5+
trait WithInit {
6+
val i = 1
37
def meth(x: Int): Int
48
}
59

610
trait Bar(x: Int)
711

8-
class C extends Foo() with Bar(1) {
12+
class NoInitClass extends NoInit() with Bar(1) {
13+
def meth(x: Int) = x
14+
}
15+
16+
class WithInitClass extends WithInit() with Bar(1) {
917
def meth(x: Int) = x
1018
}
1119

12-
object Test extends C with App
20+
object Test {
21+
def hasInit(cls: Class[_]) = cls.getMethods.map(_.toString).exists(_.contains("$init$"))
22+
def main(args: Array[String]): Unit = {
23+
val noInit = new NoInitClass {}
24+
val withInit = new WithInitClass {}
25+
26+
assert(!hasInit(noInit.getClass))
27+
assert(hasInit(withInit.getClass))
28+
}
29+
}

0 commit comments

Comments
 (0)