scala3
scala3 copied to clipboard
Compiler may not preserve the tree for `inline` macro parameters
Compiler 3.1.3 but other versions are affected too.
trait MessageMat {
inline implicit def apply(inline message: String): Message = ${ LogMessageMacro.message('message) }
}
object Message extends MessageMat {}
val m = "M E S S A G E"
val message1 = Message(
s"""This
|is a
|multiline ${m -> "message"}""".stripMargin
)
The tree for message parameter is useless because the actual expression is hidden behind a synthetic "proxy":
Apply(Select(Apply(Select(
New(Select(Select(Select(Ident(scala),collection),immutable),StringOps)),<init>),
List(Inlined(EmptyTree,List(),Inlined(EmptyTree,List(),Ident(x$proxy1))))),stripMargin),
List(Inlined(EmptyTree,List(),Inlined(EmptyTree,List(),Literal(Constant(|))))))
I strongly believe that these "proxies" (Ident(x$proxy1)) render inline parameters useless. transparent keyword on my apply signature allows me to access unmodified treel, but I strongly believe that such substitutions should not happen for inline parameters of non-transparent macros.
Context: I'm porting logstage to Scala3
Can please also provide the source of the LogMessageMacro.message I'm not able reproduce your case when proxy is introduced
Well, the code is here:
https://github.com/7mind/izumi/blob/ebdb06d447704320bec1e0ad73277686e24dd98a/logstage/logstage-core/src/main/scala-2/izumi/logstage/macros/LogMessageMacro.scala
I may implement an isolated repro, though, unfortunately, scastie does not support multiple files so that would be an sbt project.
But in fact you just need to print the tree of the message parameter in my example.