Skip to content

Can't patmat to extract type constructor from quoted type #11738

Closed
@japgolly

Description

@japgolly

Using 3.0.0-RC1, I'm trying to test whether a type is in the shape of F[A].

import scala.quoted.*

def blah[A](using Quotes, Type[A]): Expr[Unit] =
  Type.of[A] match
    case '[h *: t] => println(s"h = ${Type.show[h]}, t = ${Type.show[t]}") // ok
    case '[f[a]]   => println(s"f = ${Type.show[f]}, a = ${Type.show[a]}") // error
    case _         =>
  '{()}

The tuple case works, no problem. The f[a] case doesn't compile and instead fails with:

[error] -- [E053] Type Error: /home/golly/projects/public/univeq/univeq/shared/src/main/scala-3/japgolly/univeq/internal/test.scala:6:11 
[error] 6 |    case '[f[a]]   => println(s"f = ${Type.show[f]}, a = ${Type.show[a]}")
[error]   |           ^^^^
[error]   |           f$given1.Underlying does not take type parameters

[error] -- [E006] Not Found Error: /home/golly/projects/public/univeq/univeq/shared/src/main/scala-3/japgolly/univeq/internal/test.scala:6:69 
[error] 6 |    case '[f[a]]   => println(s"f = ${Type.show[f]}, a = ${Type.show[a]}")
[error]   |                                                                     ^
[error]   |                                                         Not found: type a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions