Skip to content

Pattern match fails at runtime when matching an module object #3179

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
nicolasstucki opened this issue Sep 26, 2017 · 1 comment
Closed

Pattern match fails at runtime when matching an module object #3179

nicolasstucki opened this issue Sep 26, 2017 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

object Test {
  def main(args: Array[String]): Unit = {
    ("": Any) match {
      case a @ Test => 1
      case _ => 2
    }
  }
}

Will fail at runtime when the matched string is casted to Test (which should not happen)

The pattern match is expanded to the following code after patternMatcher

        {
          case val x1: Any = "": Any
          case val a: Test.type = x1.asInstanceOf[Test.type]
          if Test.==(x1) then 
            {
              println(1)
            }
           else 
            {
              println(2)
            }
        }

Clearly the case val a: Test.type = x1.asInstanceOf[Test.type] should go inside the if Test.==(x1) then

@smarter
Copy link
Member

smarter commented Sep 26, 2017

Somewhat related to #1463

liufengyun added a commit to dotty-staging/dotty that referenced this issue Sep 26, 2017
liufengyun added a commit that referenced this issue Sep 27, 2017
fix #3179: bind should be nested in the plan for body
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

2 participants