-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Missing unchecked warning when pattern matching on a type parameter #1828
Comments
It seems it has something to do with the use of a generic type because if I were to hardcode
then no |
I may be able to have a look at this myself if someone can give a few pointers to where the problem might lie. |
@jedesah in scala> def unsafeCast[T](a: Any) = a match { case x: T => x; case _ => ??? }
<console>:11: warning: abstract type pattern T is unchecked since it is eliminated by erasure
def unsafeCast[T](a: Any) = a match { case x: T => x; case _ => ??? }
^
unsafeCast: [T](a: Any)T
scala> unsafeCast[String](1)
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String There is actually no typecheck here: |
Yes, pattern-matching on type parameters is unsafe and we're missing the warning, thanks for pointing that out |
@smarter Haha! Glad I could help! |
This is the same issue as #3324, will be fixed together. |
This compiles fine, but at runtime, the call to
remove
will throw ajava.lang.ClassCastException
(Integer cannot be cast to String)The text was updated successfully, but these errors were encountered: