-
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
Fix some varargs issues in scala 2 and scala 3 #433
base: main
Are you sure you want to change the base?
Conversation
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.
Hi @jxnu-liguobin, Thank you for your contribution! We really value the time you've taken to put this together. We see that you have signed the Lightbend Contributors License Agreement before, however, the CLA has changed since you last signed it. |
I don't know Scala 3 macros or the code in this library, so I'm not able to review this. |
Unfortunately this change doesn't solve the Scala 3 issue I wrote about in #354 (comment)
Output:
|
Indeed, I just realized that it only solves the problem in #354 for scala3 and scala 2. so |
Hi@SakulK ,Since inline def argss = Seq("1")
logger.info("""Hello {}""", argss*)
// also work well
logger.info("""Hello {}""", Seq(arg5ref)*)
logger.info("""Hello {}""", forceVarargs(arg5ref):_*) |
@jxnu-liguobin unfortunately the current version still doesn't help with my actual use case - calling a method that returns a
But maybe I'm missing some downside of this approach |
I think it's infeasible as SLF4j has three overloads, and we must know the size in order to choose whether to use Also, there is no support for |
@SakulK I have preliminarily solved the problem with |
Looks like it works only for statically created |
Indeed, I agree that once we if we need to match the entire syntax tree doesn't make much sense. we can add a dedicated method without |
Regarding #354
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 , #436
These two are about correctly obtaining inline parameters in scala3
To fix this, we recursively obtain the actual value of inline parameters.
For #191, we need to continue using inlining in the parameters of the wrapper function. for example. For instance:
This ensures compatibility and accurate handling of inline parameters in both Scala 2 and Scala 3.
For #436, now we can support this:
Note that this is equivalent to using hard-coded match syntax trees. Another option is to add specific APIs that do not not use
formatArgs