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 {
7
7
inline def f (sc : => scala.StringContext )(args : Any * ): String = $ { fImpl(' sc , ' args ) }
8
8
9
9
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
11
11
// 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
+ }
13
19
}
14
20
15
21
}
Original file line number Diff line number Diff line change 1
1
abc
2
- Hello world
2
+ Hello world!
3
+ Hello world!
Original file line number Diff line number Diff line change 2
2
object Test {
3
3
def main (args : Array [String ]): Unit = {
4
4
println(f " abc " )
5
- println(f " Hello ${" world" }%s " )
5
+ println(f " Hello ${" world" }%s! " )
6
+ println(f " Hello ${" world" }! " )
6
7
}
7
- }
8
+ }
You can’t perform that action at this time.
0 commit comments