Skip to content

Inconsistent matching when using type alias of Union type #8956

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
hmf opened this issue May 12, 2020 · 1 comment · Fixed by #9128
Closed

Inconsistent matching when using type alias of Union type #8956

hmf opened this issue May 12, 2020 · 1 comment · Fixed by #9128

Comments

@hmf
Copy link

hmf commented May 12, 2020

Minimized code

type Numeric = Double | Int

  val v1 = 100
  val v2 = 100.0
  def check1(i: Double | Int | String): Unit = {
    i match {
      case a:(Double | Int) => println(s"numeric = $a")
      case _ => println("categorical")
    }
  }
  /*
    [warn] 25 |      case a:Numeric => println(s"numeric = $a")
    [warn]    |           ^^^^^^^^^
    [warn]    |  the type test for gg.SlidingIssue.Numeric cannot be checked at runtime
    [warn] one warning found
   */
  def check2(i: Double | Int | String): Unit = {
    i match {
      case a:Numeric => println(s"numeric = $a")
      case _ => println("categorical")
    }
  }

Output

    [warn] 25 |      case a:Numeric => println(s"numeric = $a")
    [warn]    |           ^^^^^^^^^
    [warn]    |  the type test for gg.SlidingIssue.Numeric cannot be checked at runtime
    [warn] one warning found

Expectation

I expected that using union types directly or using a type alias should produce the same result. However when using a type alias in a match (in check1) I get the warning when using a type but not when using the unon type directly (check2).

This does not seem to happen consistently all the time.

Tested with 0.24.0-RC1

@bishabosha
Copy link
Member

this is fixed on master

@bishabosha bishabosha reopened this Jun 8, 2020
bishabosha added a commit to dotty-staging/dotty that referenced this issue Jun 8, 2020
odersky added a commit that referenced this issue Jun 8, 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