Skip to content

Commit 449aff2

Browse files
committed
Simplify extractors
1 parent ac7ab0a commit 449aff2

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,11 @@ class StringInterpolatorOpt extends MiniPhase {
3232
}
3333
}
3434

35-
private object StringContextIdent {
36-
def unapply(tree: Ident)(implicit ctx: Context): Option[Ident] = {
37-
if (tree.symbol.eq(defn.StringContextModule)) Some(tree) else None
38-
}
39-
}
40-
4135
private object StringContextApply {
42-
def unapply(tree: Select)(implicit ctx: Context): Option[Select] = {
43-
tree match {
44-
case Select(StringContextIdent(_), _)
45-
if tree.symbol.eq(defn.StringContextModule_apply) => Some(tree)
46-
case _ => None
36+
def unapply(tree: Select)(implicit ctx: Context): Boolean = {
37+
tree.symbol.eq(defn.StringContextModule_apply) && {
38+
val qualifier = tree.qualifier
39+
qualifier.isInstanceOf[Ident] && qualifier.symbol.eq(defn.StringContextModule)
4740
}
4841
}
4942
}
@@ -53,7 +46,7 @@ class StringInterpolatorOpt extends MiniPhase {
5346
def unapply(tree: Tree)(implicit ctx: Context): Option[(List[Literal], List[Tree])] = {
5447
if (tree.symbol.eq(defn.StringContextRaw) || tree.symbol.eq(defn.StringContextS)) {
5548
tree match {
56-
case Apply(Select(Apply(StringContextApply(_), List(Literals(strs))), _),
49+
case Apply(Select(Apply(StringContextApply(), List(Literals(strs))), _),
5750
List(SeqLiteral(elems, _))) if elems.length == strs.length - 1 =>
5851
Some(strs, elems)
5952
case _ => None

0 commit comments

Comments
 (0)