summaryrefslogtreecommitdiff
path: root/test/files/neg/t8431.scala
blob: bc45bb62ae4699a63cd605dcd4914a1a4d455d5f (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
trait Covariant[+A]
trait Invariant[A] extends Covariant[A @annotation.unchecked.uncheckedVariance] 
 
trait Combinable[G] {
  def combined = 0
}

trait CanBuildFrom[+C]
 
object C {
  implicit def convert1[G, TRAVONCE[+e] <: Covariant[e]]
    (xs: TRAVONCE[G]): Combinable[G] = ???
 
  implicit def convert2[G, SET[e] <: Invariant[e]]
    (xs: SET[_ <: G])
    (implicit cbf: CanBuildFrom[SET[G]]): Combinable[G] = ???

  implicit def cbf[A]: CanBuildFrom[Invariant[A]] = ???
}
// always failed
class Test1 {
  import C.{cbf, convert1, convert2}
  val s: Invariant[Nothing] = ???
  s.combined // fail
}
// didn't fail, now correctly fails
class Test2 {
  import C.{cbf, convert2, convert1}

  val s: Invariant[Nothing] = ???

  // Non-uniformity with Test1 was due to order of typechecking implicit candidates:
  // the last candidate typechecked was the only one that could contribute undetermined type parameters
  // to the enclosing context, due to mutation of `Context#undetparam` in `doTypedApply`.
  s.combined // was okay!
}


class TestExplicit {
  import C.{cbf, convert2}

  val s: Invariant[Nothing] = ???

  // Now the implicit Test fail uniformly as per this explicit conversion
  convert2(s).combined

  // Breaking this expression down doesn't make it work.
  {val c1 = convert2(s); c1.combined}
}

// These ones work before and after; inferring G=Null doesn't need to contribute an undetermined type param.
class Test3 {
   import C.{cbf, convert1, convert2}
   val s: Invariant[Null] = ???
   s.combined // okay
}

class Test4 {
   import C.{cbf, convert2, convert1}

   val s: Invariant[Null] = ???
   s.combined // okay
}