Skip to content

Cannot splice arbitary type in macros #8865

Closed
@yilinwei

Description

@yilinwei

Minimized example

import scala.quoted._
object Macro {

  def impl[A : Type](using qctx: QuoteContext): Expr[A] = {
    import qctx.tasty._
    import util._
    val tpe = typeOf[A].seal
    '{ (a: ${tpe}) => ???}
    '{???}
  }
}

Output

[error] 9 |    '{ (a: ${tpe}) => ???}
[error]   |           ^^^^^^
[error]   |           tpe.$splice cannot be used as a value type

Expectation

It should be possible to splice the type. It's also not possible to splice types which are obtained from TASTY reflect.

If we cast to Type[_ <: Any], the above snippet works. Because of this I suspect that the code isn't sound and I should be doing some form of check before splicing.

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