Skip to content

Support type bounds in quote types patterns #17810

@cchantep

Description

@cchantep

Currently not directly possible to specify type bounds in quotes type pattern.

inline def foo[T]: Unit = ${ fooImpl[T] }

private def fooImpl[T](using q: Quotes, tpe: Type[T]): Expr[Unit] = {
  import q.reflect.*

  tpe match {
    case ev @ '[t <: Product] =>
      ???
  }
}

Raise following error:

31 |      case ev @ '[t <: Product] =>
   |                    ^^
   |                    ']' expected, but '<:' found

Quotes type pattern can support type bounds as below, but not directly:

type IsProduct[U <: Product] = U

tpe match {
  case ev @ '[IsProduct[t]] =>
    ???
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions