File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
library/src-bootstrapped/scala/internal Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -7,9 +7,15 @@ object StringContext {
77 inline def f (sc : => scala.StringContext )(args : Any * ): String = $ { fImpl(' sc , ' args ) }
88
99 private def fImpl (sc : Expr [StringContext ], args : Expr [Seq [Any ]]): Expr [String ] = {
10- // TODO implement f interpolation checks and addapt sc.parts
10+ // TODO implement f interpolation checks and generate optimal code
1111 // See https://github.com/alemannosara/f-interpolators-in-Dotty-macros
12- ' { $sc.parts.mkString.format($args : _* ) }
12+ ' {
13+ // Purely runtime implementation of the f interpolation without any checks
14+ val parts = $sc.parts.toList
15+ assert(parts.nonEmpty, " StringContext should have non empty parts" )
16+ val parts2 = parts.head :: parts.tail.map(x => if (x.startsWith(" %s" )) x else " %s" + x)
17+ parts2.mkString.format($args : _* )
18+ }
1319 }
1420
1521}
Original file line number Diff line number Diff line change 11abc
2- Hello world
2+ Hello world!
3+ Hello world!
Original file line number Diff line number Diff line change 22object Test {
33 def main (args : Array [String ]): Unit = {
44 println(f " abc " )
5- println(f " Hello ${" world" }%s " )
5+ println(f " Hello ${" world" }%s! " )
6+ println(f " Hello ${" world" }! " )
67 }
7- }
8+ }
You can’t perform that action at this time.
0 commit comments