Skip to content

Improve syntax of type holes in quoted patterns #10050

Closed
@nicolasstucki

Description

@nicolasstucki

Current state

After #10045 we have the following 2 syntaxis to express a type hole in quote pattern.
The first is written using a $ on the type.

case '{ $x : $T } => '{ val y: T = .. .}

T and a given Type[T] are made available on the right-hand side of the pattern.

The second is provides a workaround to some limitations of the first syntax

case '{ type $T; $x : `$T` } => '{ val y: T = .. .}

Here the T is defined as a type in the pattern itself.
It allows us to write explicit bounds on such as

case '{ type $T <: Seq[Int]; ... } =>

It also allows us to have a spliced type that is used in several places

case '{ type $T; val x: Map[`$T`, `$T`]; ... } =>

On the other side we have known types from outside that are used in patterns which just name the type

def f[T: Type] = 
   ... match
     case '{ $x : T } => '{ val y: T = .. .}

Patterns are composable in the sense that a type extracted from one pattern can be used as a known type of a nested pattern.

match
  case '{ $x: $T } => 
    ... match 
      case '{ ... : T } => // T extracted from first match used in second

Goals

  • Remove the second syntax variant
    • Support bounds in normal holes
    • Support multiple uses of the same splice in normal holes
  • Break fake symmetry between $x and $T
  • Keep support of known types as it is
  • Type from a pattern should compose with other patterns

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