Scala: why duplicate declaration is allowed inside pattern matching?

Viewed 74

It seems that we are able to bind pattern to identifier x and then to declare one more x identifier immediately in the same scope. Why does this code work?

"123" match {
  case x@"123" =>
    // I expected compilation error here, but it actually works. Even var works
    val x = "456"
    x // "456"
}

Explaining with something like link to SLS would be especially appreciated.

1 Answers
Related