Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Support extracting higher-kinded types in quoted patterns #208

Closed
julienrf opened this issue May 12, 2021 · 1 comment
Closed

Support extracting higher-kinded types in quoted patterns #208

julienrf opened this issue May 12, 2021 · 1 comment

Comments

@julienrf
Copy link

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:

[error] 140 |        quotes.reflect.report.info(s"foo.Baz[Int] = ${Type.show[baz[Int]]}")
[error]     |                                                                ^^^^^^^^
[error]     |                                     baz does not take type parameters

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:

[error] 139 |      case '{ type baz[A]; $ignored: Foo { type Baz[A] = `baz`[A] } } =>
[error]     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |              Missing type parameter for baz

Originally posted by @julienrf in scala/scala3#12446

@nicolasstucki
Copy link

Other related issue scala/scala3#10864

@lampepfl lampepfl locked and limited conversation to collaborators Jun 5, 2023
@ckipp01 ckipp01 converted this issue into a discussion Jun 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants