-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Varargs compilation error as of v3.9.5 #354
Comments
Seems similar to #191. Starting from 3.6.0. When I remove the def infoMessageArgs(c: LoggerContext)(message: c.Expr[String], args: c.Expr[Any]*): c.universe.Tree = {
import c.universe._
val underlying = q"${c.prefix}.underlying"
// val anyRefArgs = formatArgs(c)(args: _*)
if (args.length == 2)
q"if ($underlying.isInfoEnabled) $underlying.info($message, _root_.scala.Array[AnyRef](${args.head}, ${args(1)}): _*)"
else
q"if ($underlying.isInfoEnabled) $underlying.info($message, ..$args)"
} Output
|
FYI in case someone else also runs into this, when using Scala 3 and varargs with
when running with I think the issue for Scala 3 is in this part of the macro: |
Yes, this is the same as my survey, there is an issue with the formatArgs method andScala 2 has similar issues.. |
After wrapping varargs, the user code fails to compile. In Scala 2, there were no inline parameters, and the subtype of args was obtained during compilation. However, this approach may not always be accurate. Regarding #191 There is an issue with obtaining inline parameters in Scala 3. To address this, we recursively obtain the actual value of inline parameters. This necessitates the ongoing use of inlining in the parameters of the wrapper function. For instance: ```scala class LogWrapper(val underlying: Logger) { inline def info(message: String, inline args: AnyRef*): Unit = underlying.info(message, args: _*) } ``` This ensures compatibility and accurate handling of inline parameters in both Scala 2 and Scala 3.
After wrapping varargs, the user code fails to compile. In Scala 2, there were no inline parameters, and the subtype of args was obtained during compilation. However, this approach may not always be accurate. Regarding #191 There is an issue with obtaining inline parameters in Scala 3. To address this, we recursively obtain the actual value of inline parameters. This necessitates the ongoing use of inlining in the parameters of the wrapper function. For instance: ```scala class LogWrapper(val underlying: Logger) { inline def info(message: String, inline args: AnyRef*): Unit = underlying.info(message, args: _*) } ``` This ensures compatibility and accurate handling of inline parameters in both Scala 2 and Scala 3.
The new version v3.9.5 no longer accepts the varargs logging methods being wrapped, so a class like such will fail to compile:
I've create a minimal replication repo, based on the SBT hello world template, to demonstrate how the code no longer compiles in v3.9.5.
The text was updated successfully, but these errors were encountered: