Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined error when transforming a Tasty tree and getting a type wrong #6995

Open
anatoliykmetyuk opened this issue Aug 6, 2019 · 0 comments
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:enhancement

Comments

@anatoliykmetyuk
Copy link
Contributor

minimized code

Macro:

package playground

import scala.quoted._, scala.quoted.matching._
import delegate scala.quoted._
import scala.tasty._

delegate for Toolbox = Toolbox.make(getClass.getClassLoader)

inline def mcr(x: => Any): Any = ${mcrImpl('x)}

def mcrImpl(body: Expr[Any]) given (ctx: QuoteContext): Expr[Any] = {
  import ctx.tasty._

  def transformQualifier(qual: Term): Term =
    '{
      val tmp = ${qual.seal}//.cast[Boolean]}
      tmp
    }.unseal

  val res = body.unseal.underlyingArgument match {
    case app@Apply(sel@Select(qualifier, name), args) =>
      Apply.copy(app)(
        Select.copy(sel)(transformQualifier(qualifier), name)
      , args)
  }
  res.seal
}

Main:

package playground

val a = true
@main def main = println(mcr { a && false })

Error:

[error] -- Error: /Users/anatolii/Projects/dotty/playground/core/src/main/scala/playground/Main.scala:4:31
[error] 4 |@main def main = println(mcr { a && false })
[error]   |                               ^^^^^^^^^^
[error]   |undefined: {
[error]   |  {
[error]   |    val tmp: Any =
[error]   |      {
[error]   |        playground.a
[error]   |      }
[error]   |    (tmp:Any)
[error]   |  }
[error]   |}.&& # 95367: TermRef(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),module scala),Any),&&) at frontend
[error]   | This location is in code that was inlined at Main.scala:4
[error] one error found

It works as expected if you define the tmp variable in the macro as follows:

val tmp = ${qual.seal.cast[Boolean]}

expectation

A more user-friendly message saying what exactly is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants