Skip to content

Incorrect warning “type test cannot be checked at runtime” #8932

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

Closed
julienrf opened this issue May 10, 2020 · 2 comments · Fixed by #8934
Closed

Incorrect warning “type test cannot be checked at runtime” #8932

julienrf opened this issue May 10, 2020 · 2 comments · Fixed by #8934

Comments

@julienrf
Copy link
Contributor

julienrf commented May 10, 2020

Minimized code

package bugreport

sealed trait Foo[+A]
case class Bar[A]() extends Foo[A]

def bugReport[A](foo: Foo[A]): Foo[A] =
  foo match {
    case bar: Bar[A] => bar
  }

Output

[warn] -- Warning:
[warn] 8 |    case bar: Bar[A] => bar
[warn]   |         ^^^^^^^^^^^
[warn]   |         the type test for bugreport.Bar[A] cannot be checked at runtime

Expectation

There should be no warning.

Additional information

  • There was no warning in dotty 0.24.0-RC1
  • There is no warning if type parameter A is covariant in Bar
@liufengyun
Copy link
Contributor

This is actually correct, see the example below:

sealed trait Foo[+A]
case class Bar[A]() extends Foo[A]

class Dummy extends Bar[Nothing] with Foo[String]

def bugReport[A](foo: Foo[A]): Foo[A] =
  foo match {
    case bar: Bar[A] => bar
  }

def test = bugReport(new Dummy: Foo[String])

You need to mark Bar[A] as covariant, then the warning will disappear.

liufengyun added a commit to dotty-staging/dotty that referenced this issue May 10, 2020
@julienrf
Copy link
Contributor Author

Thank you Fengyun for the detailed explanation!

liufengyun added a commit that referenced this issue May 10, 2020
julienrf added a commit to endpoints4s/endpoints4s that referenced this issue May 10, 2020
julienrf added a commit to endpoints4s/endpoints4s that referenced this issue May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants