File tree 3 files changed +15
-14
lines changed
src-bootstrapped/dotty/internal
3 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -61,19 +61,9 @@ object StringContextMacro {
61
61
import qctx .tasty ._
62
62
val sourceFile = strCtxExpr.unseal.pos.sourceFile
63
63
64
- def notStatic =
65
- qctx.throwError(" Expected statically known String Context" , strCtxExpr)
66
- def splitParts (seq : Expr [Seq [String ]]) = seq match {
67
- case Varargs (p1) =>
68
- p1 match
69
- case Consts (p2) => (p1.toList, p2.toList)
70
- case _ => notStatic
71
- case _ => notStatic
72
- }
73
64
val (partsExpr, parts) = strCtxExpr match {
74
- case ' { StringContext ($parts : _* ) } => splitParts(parts)
75
- case ' { new StringContext ($parts : _* ) } => splitParts(parts)
76
- case _ => notStatic
65
+ case Expr .StringContext (p1 @ Consts (p2)) => (p1.toList, p2.toList)
66
+ case _ => qctx.throwError(" Expected statically known String Context" , strCtxExpr)
77
67
}
78
68
79
69
val args = argsExpr match {
Original file line number Diff line number Diff line change @@ -38,10 +38,10 @@ package object compiletime {
38
38
transparent inline def (inline self : StringContext ) code (inline args : Any * ): String = $ { codeExpr(' self , ' args ) }
39
39
private def codeExpr (using qctx : QuoteContext )(sc : Expr [StringContext ], args : Expr [Seq [Any ]]): Expr [String ] =
40
40
(sc, args) match
41
- case (' { StringContext ($ { Varargs ( Consts (parts))} : _* ) } , Varargs (args2)) =>
41
+ case (Expr . StringContext (Consts (parts)), Varargs (args2)) =>
42
42
Expr (StringContext (parts : _* ).s(args2.map(_.show): _* ))
43
43
case _ =>
44
- qctx.throwError(" compiletime.code must be used as a string interpolator code\" ...\" " )
44
+ qctx.throwError(" compiletime.code must be used as a string interpolator ` code\" ...\" ` " )
45
45
46
46
inline def constValueOpt [T ]: Option [T ] = ???
47
47
Original file line number Diff line number Diff line change @@ -219,4 +219,15 @@ object Expr {
219
219
}
220
220
}
221
221
222
+ object StringContext {
223
+ /** Matches a `StringContext(part0, part1, ...)` and extracts the parts of a call to if the
224
+ * parts are passed explicitly. Returns the equvalent to `Seq('{part0}, '{part1}, ...)`.
225
+ */
226
+ def unapply (sc : Expr [StringContext ])(using QuoteContext ): Option [Seq [Expr [String ]]] =
227
+ sc match
228
+ case ' { scala.StringContext ($ {Varargs (parts)}: _* ) } => Some (parts)
229
+ case ' { new scala.StringContext ($ {Varargs (parts)}: _* ) } => Some (parts)
230
+ case _ => None
231
+ }
232
+
222
233
}
You can’t perform that action at this time.
0 commit comments