Closed
Description
Compiler version
Minimized code
macros.scala
:
import scala.quoted.{Quotes, Expr, quotes}
inline def assertTrue(cond: Boolean) =
${ assertTrueImpl('cond) }
def assertTrueImpl(cond: Expr[Boolean])(using Quotes) =
'{ if (!$cond) throw new Error(${'{""}}) }
Test.scala
:
object Test:
def main(args: Array[String]) =
try assertTrue(1 == 2) catch e => println(e.getStackTrace()(0))
try assertTrue(1 == 3) catch e => println(e.getStackTrace()(0))
Output
Test$.main(Test.scala:5)
Test$.main(Test.scala:5)
Expectation
Test$.main(Test.scala:3)
Test$.main(Test.scala:4)
Cause
The content of the inner quote gets a wrong position:
new Error@<macros.scala:7>@<macros.scala:7>@<macros.scala:7>(
""@<Test.scala:5>@<macros.scala:7>
)@<macros.scala:7>
I think that this is due to Positioned#cloneIn
not updating Positioned#source
(origin: #9900).