aboutsummaryrefslogtreecommitdiff
path: root/tests/neg/hk-bounds.scala
blob: 628d200c23599f5adfa85bc249264d2168dba21e (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
class Foo[A]
class Bar[B]
class Baz[C] extends Bar[C]

object Test1 {
  type Alias[F[X] <: Foo[X]] = F[Int]

  val x: Alias[Bar] = new Bar[Int] // error: Type argument [X0] => Bar[X0] does not conform to upper bound [X0] => Foo[X0]

  def foo[F[X] <: Foo[X]] = ()
  foo[Bar] // error: Type argument [X0] => Bar[X0] does not conform to upper bound [X0] => Foo[X0]

  def bar[B[X] >: Bar[X]] = ()
  bar[Bar] // ok
  bar[Baz] // // error: Type argument [X0] => Baz[X0] does not conform to lower bound [X0] => Bar[X0]
  bar[Foo] // error: Type argument [X0] => Foo[X0] does not conform to lower bound [X0] => Bar[X0]

  def baz[B[X] >: Baz[X]] = ()
  baz[Bar] //ok
  baz[Baz] //ok
  baz[Foo] // error: Type argument [X0] => Foo[X0] does not conform to lower bound [X0] => Baz[X0]

}
object Test2 {
  type Alias[F[X] <: Foo[X]] = F[Int]

  def foo[M[_[_]], A[_]]: M[A] = null.asInstanceOf[M[A]]

  val x = foo[Alias, Bar] // error: Type argument Test2.Alias does not conform to upper bound [X0 <: [X0] => Any] -> Any

}