Skip to content

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

Closed
@nicolasstucki

Description

@nicolasstucki
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions