summaryrefslogtreecommitdiff
path: root/test/files/run/overloads.scala
blob: 461633ce67aeedfdf37243233d3ee436128c9460 (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
//############################################################################
// Overloads
//############################################################################
// $Id$

//############################################################################

object M1 {
    def f[A](x: A) = 11;
    def f[A <: StructuralEquality[A]](x: A) = 12;
}

object M2 {
    def f[A <: StructuralEquality[A]](x: A) = 21;
    def f[A](x: A) = 22;
}

object overloads {

    def check(what: String, actual: Any, expected: Any): Unit = {
        val success: Boolean = actual == expected;
        System.out.print(if (success) "ok" else "KO");
        var value: String = if (actual == null) "null" else actual.toString();
        if (value == "\u0000") value = "\\u0000";
        System.out.print(": " + what + " = " + value);
        if (!success) System.out.print(" != " + expected);
        System.out.println();
        System.out.flush();
    }

    def test: Unit = {
        val x = 3;
        check("M1.f(" + x +")", M1.f(x), 11);
        check("M2.f(" + x +")", M2.f(x), 22);
        val y = new scala.collection.mutable.Stack[Int];
        check("M1.f(" + y +")", M1.f(y), 12);
        check("M2.f(" + y +")", M2.f(y), 21);
    }

}

//############################################################################

object Test {

  def main(args: Array[String]): Unit = {
    overloads.test;
  }

}

//############################################################################