Skip to content

Incorrect error message for unsafe patterns in val/var defs #6621

@OlivierBlanvillain

Description

@OlivierBlanvillain
object Unapply {
  def unapply(a: Any): Option[(Int, Int)] =
    Some((1, 2))
}

object Test {
  val Unapply(x, y) = ""
}

Compiled with -language:3.1:

7 |  val Unapply(x, y) = ""
  |      ^^^^^^^^^^^^^
  |pattern's type String is more specialized than the right hand side expression's type String("")
  |
  |If the narrowing is intentional, this can be communicated by writing `: @unchecked` after the full pattern.
one error found

Metadata

Metadata

Assignees

Labels

area:reportingError reporting including formatting, implicit suggestions, etc

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions