How to extract a higher-kinded type in a quoted pattern? #12446
Answered
by
nicolasstucki
julienrf
asked this question in
Metaprogramming
-
Consider the following macro definition: import scala.quoted.*
trait Foo:
type Bar
type Baz[A]
inline def macroDef(foo: Foo) = ${ macroImpl('foo) }
def macroImpl(foo: Expr[Foo])(using Quotes): Expr[Unit] =
foo match
case '{ $ignored: Foo { type Bar = bar } } =>
quotes.reflect.report.info(s"foo.Bar = ${Type.show[bar]}")
foo match
case '{ $ignored: Foo { type Baz[A] = baz } } =>
quotes.reflect.report.info(s"foo.Baz[Int] = ${Type.show[baz[Int]]}")
'{ () } The first match expression does work and prints something during the macro expansion, however, the second match expression does not even compile, it says:
I’ve tried different variations, without success: case '{ $ignored: Foo { type Baz[A] = baz } } =>
quotes.reflect.report.info(s"foo.Baz = ${Type.show[baz]}") This one compiles but does not match at macro-expansion-time. case '{ type baz[A]; $ignored: Foo { type Baz[A] = `baz`[A] } } =>
quotes.reflect.report.info(s"foo.Baz[Int] = ${Type.show[baz[Int]]}") This one does not compile:
|
Beta Was this translation helpful? Give feedback.
Answered by
nicolasstucki
May 12, 2021
Replies: 1 comment
-
We are still missing support for higher-kinded type holes |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nicolasstucki
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We are still missing support for higher-kinded type holes