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

No warning on typecase pattern involving a case class #11178

Closed
abgruszecki opened this issue Jan 20, 2021 · 2 comments · Fixed by #11768
Closed

No warning on typecase pattern involving a case class #11178

abgruszecki opened this issue Jan 20, 2021 · 2 comments · Fixed by #11768
Assignees
Milestone

Comments

@abgruszecki
Copy link
Contributor

Minimized code

   trait Box[+T]
   case class Foo[+S](s: S) extends Box[S]

   def unwrap2[A](b: Box[A]): A =
     b match
     case _: Foo[Int] => 0 // compiles, not ok

Output

Compiles with no warning, which is not OK.

Expectation

At least a warning about a pattern that cannot be checked at runtime should be emitted. The code shouldn't typecheck as well, but that's a secondary problem.

@liufengyun
Copy link
Contributor

Seems related to #4298

@adpi2
Copy link
Member

adpi2 commented Feb 22, 2021

I came across the same error and I found that a warning is issued if the type is invariant but not if it's covariant or contravariant:

// Invariant case, OK
sealed trait Bar[A]

def test[A](bar: Bar[A]) =
  bar match {
    case _: Bar[Boolean] => ??? // unchecked warning, OK
    case _ => ???
  }
// Covariant case, not OK
sealed trait Bar[+A]

def test[A](bar: Bar[A]) =
  bar match {
    case _: Bar[Boolean] => ??? //  no warning, not OK
    case _ => ???
  }
// Contravariant case, not OK
sealed trait Bar[-A]

def test[A](bar: Bar[A]) =
  bar match {
    case _: Bar[Boolean] => ??? // no warning, not OK
    case _ => ???
  }

liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 16, 2021
This reverts scala#9789. We have made several improvements to F-bounds,
the unsound tweak is no longer needed.
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 16, 2021
This reverts scala#9789. We have made several improvements to F-bounds,
the unsound tweak is no longer needed.
liufengyun added a commit to dotty-staging/dotty that referenced this issue Mar 17, 2021
This reverts scala#9789. We have made several improvements to F-bounds,
the unsound tweak is no longer needed.
@liufengyun liufengyun added this to the 3.0.0-RC2 milestone Mar 17, 2021
liufengyun added a commit that referenced this issue Mar 17, 2021
Fix #11178: remove unsound tweak for F-bounds in isInstanceOf check
michelou pushed a commit to michelou/dotty that referenced this issue Mar 22, 2021
This reverts scala#9789. We have made several improvements to F-bounds,
the unsound tweak is no longer needed.
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC2, 3.0.0 Aug 2, 2023
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.

4 participants