Skip to content

Type annotations for patterns #1308

@jiribenes

Description

@jiribenes

Currently, we can't write the : Int part of

expr match {
  case Cons(x: Int, _) => x // doesn't parse, "Expected ) but got :"
  ...
}

similarly, we can't use it in if (expr is Some(x: String)) and val Some(b: Bool) = expr.

This is especially annoying for tuple parameters

// argument list works
def f { g: (Int, String) => Unit }: Unit = g(0, "")
f { (x: Int, y) => () } // works (and reports an error if the annotation is wrong)

// tuple does not
def f { g: ((Int, String)) => Unit }: Unit = g((0, ""))
f { case (x: Int, y) => () } // doesn't parse, "Expected ) but got :"

However, I do not want to use it for runtime matching like in Scala:

// not this, please
expr match {
  case n: Int => ...
  case s: String => ...
  case _ => panic("ohno")
}

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