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

Missing unchecked warning for isInstanceOf checks #3324

Closed
allanrenucci opened this issue Oct 13, 2017 · 4 comments
Closed

Missing unchecked warning for isInstanceOf checks #3324

allanrenucci opened this issue Oct 13, 2017 · 4 comments

Comments

@allanrenucci
Copy link
Contributor

This code snippet emits a warning with scalac but not with Dotty

class Foo {
  def foo(x: Any): Boolean =
    x.isInstanceOf[List[String]]
}
Foo.scala:3: warning: non-variable type argument String in type List[String] (the underlying of List[String]) is unchecked since it is eliminated by erasure
    x.isInstanceOf[List[String]]
                  ^
one warning found
@odersky
Copy link
Contributor

odersky commented Oct 14, 2017

I am not sure what we want to spec here, yet.

@odersky
Copy link
Contributor

odersky commented Oct 25, 2017

I now think we should do the same as scalac.

@allanrenucci
Copy link
Contributor Author

For (x: X).isInstanceOf[P], scalac emits an unchecked warning when:

We designate another type, XR, which is essentially the intersection of X and |P|, where |P| is the erasure of P. If XR <: P, then no warning is emitted.

ref: https://github.com/scala/scala/blob/94cee79eb63b4449d21dc74cb9175d6412cc8a55/src/compiler/scala/tools/nsc/typechecker/Checkable.scala#L12-L64

@odersky
Copy link
Contributor

odersky commented Feb 26, 2018

It's actually a wider problem: Consider:

class C[T] {
  val x: Any = ???
  if (x.isInstanceOf[List[String]]) // error: unchecked
    if (x.isInstanceOf[T])          // error: unchecked
      x match {
        case x: List[String] =>     // error: unchecked
        case x: T =>                // error: unchecked
      }
}

scalac will issue an unchecked warning at each line. Dotty remains silent.

@odersky odersky removed their assignment Feb 26, 2018
@liufengyun liufengyun self-assigned this Feb 26, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 27, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 1, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 2, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 6, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 9, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 23, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 26, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 27, 2018
add check for runtime realizability of type test
liufengyun added a commit to dotty-staging/dotty that referenced this issue Apr 5, 2018
add check for runtime realizability of type test
liufengyun added a commit that referenced this issue Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants