Skip to content

Commit 1e6ce2a

Browse files
author
Sara Alemanno
committed
Modify expression extraction
1 parent db2b39d commit 1e6ce2a

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

library/src-3.x/dotty/internal/StringContextMacro.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,9 @@ object StringContextMacro {
7171
*/
7272
def getPartsExprs(strCtxExpr : Expr[scala.StringContext])(implicit reflect : Reflection): List[Expr[String]] = {
7373
import reflect._
74-
strCtxExpr.unseal.underlyingArgument match {
75-
case Apply(Select(Select(_, "StringContext") | Ident("StringContext"), "apply"), List(parts1)) =>
76-
parts1.seal.cast[Seq[String]] match {
77-
case ExprSeq(parts2) => parts2.toList
78-
case _ => QuoteError("Expected statically known String Context", strCtxExpr)
79-
}
80-
case Apply(Select(New(TypeIdent("StringContext")), _), List(parts1)) =>
81-
parts1.seal.cast[Seq[String]] match {
82-
case ExprSeq(parts2) => parts2.toList
83-
case _ => QuoteError("Expected statically known String Context", strCtxExpr)
84-
}
74+
strCtxExpr match {
75+
case '{ StringContext(${ExprSeq(parts)}: _*) } => parts.toList
76+
case '{ new StringContext(${ExprSeq(parts)}: _*) } => parts.toList
8577
case _ => QuoteError("Expected statically known String Context", strCtxExpr)
8678
}
8779
}

tests/run-macros/f-interpolator-neg/Macros_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Macro {
1717
(strCtxExpr, argsExpr) match {
1818
case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) =>
1919
val errors = List.newBuilder[Expr[(Boolean, Int, Int, Int, String)]]
20-
// true if error, false if warning
20+
// true if error, false if warning
2121
// 0 if part, 1 if arg, 2 if strCtx, 3 if args
2222
// index in the list if arg or part, -1 otherwise
2323
// offset, 0 if strCtx, args or arg
@@ -67,7 +67,7 @@ object Macro {
6767
errors.result().toExprOfList
6868
case ('{ new StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) =>
6969
val errors = List.newBuilder[Expr[(Boolean, Int, Int, Int, String)]]
70-
// true if error, false if warning
70+
// true if error, false if warning
7171
// 0 if part, 1 if arg, 2 if strCtx, 3 if args
7272
// index in the list if arg or part, -1 otherwise
7373
// offset, 0 if strCtx, args or arg

0 commit comments

Comments
 (0)