-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Minimized code
In MacrosBug1.scala
file I have:
object MacrosBug1 {
import scala.quoted._
object Exp {
inline private def compileImpl(e: Expr[Int], env: Map[String, Expr[Int]])(using QuoteContext): Expr[Int] = {
e match {
case '{$s:Int} => s
case exp =>
compileImpl(exp, env)
}
}
private def compileUnlift(e: Expr[Int])(using QuoteContext): Expr[Int] = {
val environment = Map[String, Expr[Int]]()
compileImpl(e, environment)
}
inline def compile(inline expr: Int): Int = {
${compileUnlift('expr)}
}
}
}
Notice how compileImpl
has been inlined.
In MacrosBugMain.scala
file I have:
object MacrosBugMain {
def main(args: Array[String]): Unit = {
println("Hello world!")
// MacrosBug1
//println(compile(3))
}
}
Output
[info] Compiling 2 Scala sources to /home/hmf/IdeaProjects/snol/out/tutorial/compile/dest/classes ...
[error] -- Error: /home/hmf/IdeaProjects/snol/tutorial/src/dotty/MacrosBug1.scala:18:6 -
[error] 18 | compileImpl(e, environment)
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | Maximal number of successive inlines (32) exceeded,
[error] | Maybe this is caused by a recursive inline method?
[error] | You can use -Xmax-inlines to change the limit.
[error] | This location contains code that was inlined from MacrosBug1.scala:18
[error] | This location contains code that was inlined from MacrosBug1.scala:12
...
Expectation
Seeing as I have commented out //println(compile(3))
I do not expect the macro to be used during compilation. If I do add that code then I get the expected error:
[error] -- Error: /home/hmf/IdeaProjects/snol/tutorial/src/dotty/MacrosBugMain.scala:17:19
[error] 17 | println(compile(3))
[error] | ^^^^^^^^^^
[error] | Could not find class dotty.MacrosBug1$Exp$ in classpath
[error] | This location contains code that was inlined from MacrosBugMain.scala:17
From a user's point of view this seems to be a bug.
TIA