Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unchecked warning missing when enclosing class type parameter is used as a type argument #9188

Open
scabug opened this issue Feb 27, 2015 · 5 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 27, 2015

class A[K] {
  def receive: PartialFunction[Any, Unit] = {
    case ds: List[Double] =>  // unchecked warning
      println("* List[Double]")
    case kx: Vector[K] =>      // no unchecked warning
      println("* Vector[K]")
    case ak: A[K] =>          // no unchecked warning
      println("* A[K]")
  }
}
@scabug
Copy link
Author

scabug commented Feb 27, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9188?orig=1
Reporter: Chifeng Chou (cfchou)
Affected Versions: 2.11.6

@scabug
Copy link
Author

scabug commented Feb 27, 2015

@retronym said:
scala/scala#4366

@scabug
Copy link
Author

scabug commented Feb 27, 2015

@retronym said:
Turns out the fix is a little harder than I thought. I'll have to circle back to this ticket later.

@scabug
Copy link
Author

scabug commented Mar 4, 2015

@som-snytt said:
Maybe related lack of warning from SO.

"Any" seems to mean: OK, I don't need to help you anymore.

http://stackoverflow.com/questions/28859882/is-it-a-type-checker-bug

Similar to the SO example:

scala> import concurrent._,ExecutionContext.Implicits.global
import concurrent._
import ExecutionContext.Implicits.global

scala> trait Verify[A] { def apply(a: A): Boolean }
defined trait Verify

scala> case class FV[A](f: Future[A], v: Verify[A])
defined class FV

scala> val vint = new Verify[Int] { def apply(i: Int) = i == 42 }
vint: Verify[Int] = $anon$1@15ff3e9e

scala> val x = FV(Future(3), vint)
x: FV[Int] = FV(scala.concurrent.impl.Promise$DefaultPromise@291caca8,$anon$1@15ff3e9e)

scala> (x: FV[_]) match { case FV(f: Future[String], v) => v(f.value.get.get) }
<console>:17: warning: non-variable type argument String in type pattern scala.concurrent.Future[String] is unchecked since it is eliminated by erasure
              (x: FV[_]) match { case FV(f: Future[String], v) => v(f.value.get.get) }
                                            ^
res1: Boolean = false

scala> (x: FV[_]) match { case FV(f: Future[Any], v) => v(f.value.get.get) }
res2: Boolean = false

scala> (x: FV[_]) match { case FV(f: Future[Any], v) => v("nope") }
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
  at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:105)
  at $anon$1.apply(<console>:12)
  ... 33 elided

@scabug
Copy link
Author

scabug commented Oct 22, 2015

@SethTisue said (edited on Oct 22, 2015 1:14:43 AM UTC):
golfed

class C[T] { (0: Any) match { case _: C[T] => } } // wtf y u no warn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants