Skip to content

Spec: Are blocks allowed in patterns? #1774

@liufengyun

Description

@liufengyun

Scalac doesn't parse following programs syntactically, but support it if it's synthesized.

Dotty accepts the code syntactically, but the typer generates a typing error.

object Test {
  val a = (3, 4) match {
    case ({name: Int}, {parent: Int}) => (name, parent)
  }

  val name = a._1
  val parent = a._2
}

Error message:

-- Error: examples/block.scala -------------------------------------------------
6 |  val name = a._1
  |             ^
  |             cyclic reference involving value a
-- Error: examples/block.scala -------------------------------------------------
7 |  val parent = a._2
  |               ^
  |               cyclic reference involving value a
-- Error: examples/block.scala -------------------------------------------------
3 |    case ({name: Int}, {parent: Int}) => (name, parent)
  |                                          ^^^^
  |                                        cyclic reference involving value a

three errors found

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