aboutsummaryrefslogtreecommitdiff
path: root/tests/neg/t2660.scala
blob: 17fe262585ab928484c2d9272e84907eb154eff1 (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
// Dotty deviation. The calls here now are classified as ambiguous.

package hoho

class G

class H extends G

class A[T](x: T) {

  def this(y: G, z: T) = {
    this(z)
    print(1)
  }

  def this(z: H, h: T) = {
    this(h)
    print(2)
  }
}

object T {
  def main(args: Array[String]): Unit = {
    implicit def g2h(g: G): H = new H
    new A[Int](new H, 23)                             // error
      // in the context here, either secondary constructor is applicable
      // to the other, due to the implicit in scope. So the call is ambiguous.
  }
}


// A version of t2660 which does not use constructors

object X {
  def f[T](x: T) = ???
  def f[T](y: G, z: T) = ???
  def f[T](z: H, h: T) = ???
}

object T2 {
  def main(args: Array[String]): Unit = {
    implicit def g2h(g: G): H = new H
    X.f(new H, 23)                                    // error
  }
}