aboutsummaryrefslogtreecommitdiff
path: root/tests/run/t1381.scala
blob: c7f49c6c369fcb6d0cef1be2154cc839d4a8430a (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
object Test {
  def main(args: Array[String]): Unit = {
    Test1.test()
    Test2.test()
    Test3.test()
  }
}

object Test1 {
  class Bar[T](n: Int) {
    println(n)
  }
  implicit def const[T](x: T): Bar[T] = new Bar[T](1)

  def bar[T](e: T): Any = new Bar[T](2)
  def bar[T](e: Bar[T]): Any = new Bar[T](3)

  val b: Bar[Int] = new Bar[Int](4)

  def test(): Unit = {
    bar(b)
    bar(5)
  }
}

object Test2 {
  trait A; trait B
  class C1 {
    def f(x: A): Unit = println("A")
  }
  class C2 extends C1 {
    def f(x: B): Unit = println("B")
  }
  object Test extends C2 with App {
    implicit def a2b(x: A): B = new B {}
    def test(): Unit = {
      f(new A {})
      f(new B {})
    }
  }
  def test(): Unit = Test.test()
}

object Test3 {
  trait A; trait B
  class C extends A with B
  def fr(x: A): A = {
    println("frA")
    x
  }
  def fr(x: B): B = {
    println("frB")
    x
  }
  def test(): Unit = {
    val a: A = fr(new C)
    val b: B = fr(new C)
  }
}