It is so easy in Scala 2, just:
q"lazy val $name = $value"
I need it for local values, so I don't have multi-thread requirements
I've tried just adding Flags.Lazy to the val definition equivalent:
val symbol = Symbol.newVal(
Symbol.spliceOwner,
name,
TypeRepr.of[T],
Flags.Lazy,
Symbol.noSymbol
)
ValDef(symbol, Some(value.asTerm.changeOwner(symbol)))
But it doesn't work in Scala 3.3.6 (the latest LTS) and values generated by it fail to compile with the following error: "x is a forward reference extending over the definition of x"
While Scala 2 version works as expected helping me to resolve the forward reference issue
lazy valto handle recursion in definition? Is it possible that after building the whole tree definitions might be used out of order? I checked that I am buildinglazy vals in exactly the same way, they are working and-Xcheck-macrosdoes not complain.x is a forward reference extending over the definition of x