aboutsummaryrefslogtreecommitdiff
path: root/tests/run/mixins.scala
blob: 23aec6b52488e67777ff02c253b6d943829f96c0 (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
// Test 1: "super" coming from mixins

import Console._;

object Test1 {
  class A {
    def f = "A::f";
  }

  class B extends A {
    override def f = "B::f";
  }

  trait M1 extends A {
    override def f = "M1::" + super.f;
  }

  class C extends B with M1 {
    override def f = super[M1].f;
  }

  def test(): Unit = {
    val c = new C;
    Console.println(c.f);
  }
}

// Test 2: qualified "super" inside of the host class

object Test2 {
  class M1 {
    def f = "M1::f";
  }

  trait M2 {
    def f = "M2::f";
  }

  trait M3 {
    def f = "M3::f";
  }

  class Host extends M1 with M2 with M3 {
    override def f = super[M1].f + " " + super[M2].f + " " + super[M3].f
  }

  def test(): Unit = {
    val h = new Host;
    Console.println(h.f)
  }
}

// Test 3: mixin evaluation order (bug 120)

object Test3 {

  class A(x: Unit, y: Unit) {
    Console.println("A");
  }

  trait B {
    println("B");
  }

  class C extends A({ println("one"); }, { println("two"); })
          with B {
    println("C");
  }

  def test() = {
    val c = new C();
  }
}

// Main testing function

object Test {
  def main(args: Array[String]): Unit = {
    Test1.test();
    Test2.test();
    Test3.test();
  }
}