Skip to content

Commit f04972f

Browse files
committed
Normalize tree before pattern matching
1 parent 41d24df commit f04972f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

library/src-bootstrapped/scala/runtime/quoted/Matcher.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,19 @@ object Matcher {
4747
if (scrutinees.size != patterns.size) None
4848
else foldMatchings(scrutinees.zip(patterns).map(treeMatches): _*)
4949

50-
(scrutinee, pattern) match {
51-
// Normalize blocks without statements
52-
case (Block(Nil, expr), _) => treeMatches(expr, pattern)
53-
case (_, Block(Nil, pat)) => treeMatches(scrutinee, pat)
50+
def normalize(tree: Tree): Tree = tree match {
51+
case Block(Nil, expr) => normalize(expr)
52+
case Inlined(_, Nil, expr) => normalize(expr)
53+
case _ => tree
54+
}
55+
56+
(normalize(scrutinee), normalize(pattern)) match {
5457

5558
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
5659
case (IsTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
5760
if patternHole.symbol == kernel.Definitions_InternalQuoted_patternHole && scrutinee.tpe <:< tpt.tpe =>
5861
Some(Tuple1(scrutinee.seal))
5962

60-
// Normalize inline trees
61-
case (Inlined(_, Nil, scr), _) => treeMatches(scr, pattern)
62-
case (_, Inlined(_, Nil, pat)) => treeMatches(scrutinee, pat)
63-
6463
//
6564
// Match two equivalent trees
6665
//

0 commit comments

Comments
 (0)