Skip to content

Unreachability check for pattern is not precise enough when the scrutinee is a union #8711

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
smarter opened this issue Apr 12, 2020 · 0 comments · Fixed by #8722
Closed

Comments

@smarter
Copy link
Member

smarter commented Apr 12, 2020

class A
class B
class C

object Test {
  def foo(x: A) = x match {
    case x: B => x // as expected, error: this case is unreachable since class A is not a subclass of class B
    case _ =>
  }

  def bar(x: A | B) = x match {
    case x: C => x // no error!
    case _ =>
  }
}

The logic handling this is in TypeTestCast#interceptTypeApply#interceptWith#transformIsInstanceOf which computes a class symbol for the scrutinee:

      def foundCls = effectiveClass(expr.tpe.widen)

So when the pattern has type A | B, testCls will be Any. This logic needs to be adapted to handle union types where there's more than one possible class symbol.

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