-
Notifications
You must be signed in to change notification settings - Fork 1.1k
f-interpolator parity #9939
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
Comments
scala> f"${0}%n"
val res1: String = "
" |
scala> f"${0}%d"
val res9: String = 0
scala> f"${0}%%d"
val res10: String = %d
scala> f"${0}%%%d"
val res11: String = %0
scala> f"${0}%%%%d"
val res12: String = %%d
scala> f"${0}%%%%%d"
val res13: String = %%0 expected scala 2.13.3> f"${0}%d"
val res21: String = 0
scala 2.13.3> f"${0}%%d"
val res22: String = 0%d
scala 2.13.3> f"${0}%%%d"
^
error: conversions must follow a splice; use %% for literal %, %n for newline
scala 2.13.3> f"${0}%%%%d"
val res24: String = 0%%d
scala 2.13.3> f"${0}%%%%%d"
^
error: conversions must follow a splice; use %% for literal %, %n for newline |
I guess we should just port the implementation from Scala 2. We can port it in |
I took a few minutes to try these examples from the scala 2 tests, and a minute more to look at fixing. I'll try to make time, modulo day job and pandemic sleep schedule. It's not obvious that keeping the old code is desirable. Also, it's tiresome to hear "String.format is slow." It would be nice to have |
Thanks @som-snytt for looking into it, I assigned you to the issue. |
Compare
|
Cf #10315 |
Classic example from Scanners:
Doesn't do escaped slash, doesn't take char as int. Edit: actually, doesn't do any escape processing. |
Fixes the following sample from scala#9939: ```scala scala> f"${3.14}%.2f rounds to ${3}%d" 1 |f"${3.14}%.2f rounds to ${3}%d" | ^ | type mismatch; | found : Double | required: Int | This location contains code that was inlined from rs$line$2:1 ``` At the moment when StringInterpolation transfomation was perfomed instead of receiving `List(Constant(3.0), Constant(3))` arguments they were: `List(Constant(3.0), Constant(3.0))` (the second one was converted to double because of harmonization). That caused the reported type mismatch. In Scala2 harmonization doesn't happen if the resulting type is fully defined. For f-interp it shouldn't happen too as it's resulting type is a `String`: ```scala def f[A >: Any](args: A*): String = macro ??? ```
Fixes the following sample from scala#9939: ```scala scala> f"${3.14}%.2f rounds to ${3}%d" 1 |f"${3.14}%.2f rounds to ${3}%d" | ^ | type mismatch; | found : Double | required: Int | This location contains code that was inlined from rs$line$2:1 ``` At the moment when StringInterpolation transformation was performed instead of receiving `List(Constant(3.0), Constant(3))` arguments they were: `List(Constant(3.0), Constant(3.0))` (the second one was converted to double because of harmonization). That caused the reported type mismatch. In Scala2 harmonization doesn't happen if the resulting type is fully defined. For f-interp it shouldn't happen too as it's resulting type is a `String`: ```scala def f[A >: Any](args: A*): String = macro ??? ```
Noting the efficacy of |
Fixes the following sample from scala#9939: ```scala scala> f"${3.14}%.2f rounds to ${3}%d" 1 |f"${3.14}%.2f rounds to ${3}%d" | ^ | type mismatch; | found : Double | required: Int | This location contains code that was inlined from rs$line$2:1 ``` At the moment when StringInterpolation transformation was performed instead of receiving `List(Constant(3.0), Constant(3))` arguments they were: `List(Constant(3.0), Constant(3.0))` (the second one was converted to double because of harmonization). That caused the reported type mismatch. In Scala2 harmonization doesn't happen if the resulting type is fully defined. For f-interp it shouldn't happen too as it's resulting type is a `String`: ```scala def f[A >: Any](args: A*): String = macro ??? ```
Minimized code
Output
// as shown
Expectation
The text was updated successfully, but these errors were encountered: