File: unchecked-refinement.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (27 lines) | stat: -rw-r--r-- 965 bytes parent folder | download | duplicates (4)
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
// a.scala
// Thu Sep 27 09:42:16 PDT 2012

trait Bar[-T1, T2, +T3] { }
trait Foo[-T1, T2, +T3] extends Bar[T1, T2, T3]

class A {
  var b = true

  def f1(x: Foo[Int, Int, Int]) = x match {
    /* nowarn */ case _: Foo[Nothing, Int, Any] => true
  }
  def f2[T, U, V](x: Foo[T, U, V]) = x match {
    /* nowarn */ case _: Foo[Nothing, U, Any] => true
  }
  def f3[T, U, V](x: Foo[T, U, V]) = x match {
    /*   warn */ case _: Foo[U, U, V] if b       => ()
    /* nowarn */ case _: Foo[Nothing, U, V] if b => ()
    /*   warn */ case _: Foo[Any, U, V] if b     => ()
  }

  def f4(xs: List[Int]) = xs match {
    /* nowarn - todo */ case x: AnyRef { def bippy: Int } if b => x.bippy  // this could/should do an instance check and not warn
    /* nowarn - todo */ case x: AnyRef { def size: Int } if b  => x.size   // this could/should do a static conformance test and not warn
    /* nowarn */ case x: ((AnyRef { def size: Int }) @unchecked) if b  => x.size
  }
}