Skip to content

ValDef: ClassCastException: Trees$Select cannot be cast to Trees$Ident #12584

Closed
@scf37

Description

@scf37

Compiler version

3.0.0

Minimized code

Macro.scala

import scala.deriving._
import scala.compiletime._
import scala.quoted._

object Macro:
  inline def impl: Any = ${doImpl}

  def doImpl(using Quotes): Expr[Any] =
    import quotes.reflect._
    ValDef.let(Symbol.classSymbol("Macro"), "param", Expr(42).asTerm) { nameRef =>
      Expr(11).asTerm
    }.asExpr

Main.scala

class Main:
  val useIt = Macro.impl

Output (click arrow to expand)

[info] compiling 2 Scala sources to /tmp/1/target/scala-3.0.0/classes ...
[error] -- Error: /tmp/1/Main.scala:2:20 -----------------------------------------------
[error] 2 |  val useIt = Macro.impl
[error]   |              ^^^^^^^^^^
[error]   |Exception occurred while executing macro expansion.
[error]   |java.lang.ClassCastException: dotty.tools.dotc.ast.Trees$Select cannot be cast to dotty.tools.dotc.ast.Trees$Ident
[error]   |	at scala.quoted.runtime.impl.QuotesImpl$reflect$ValDef$.let(QuotesImpl.scala:291)
[error]   |	at scala.quoted.runtime.impl.QuotesImpl$reflect$ValDef$.let(QuotesImpl.scala:289)
[error]   |	at Macro$.doImpl(Macro.scala:11)
[error]   |
[error]   | This location contains code that was inlined from Main.scala:2
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions