Skip to content

Commit cc34a88

Browse files
committed
Fail fast for hole pattterns
1 parent 9df6f90 commit cc34a88

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,30 @@ object QuoteMatcher {
181181
case _ => None
182182
end TypeTreeTypeTest
183183

184-
val res = (scrutinee, pattern) match
184+
val res = pattern match
185185

186186
/* Term hole */
187187
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
188-
case (Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2))
188+
case Typed(TypeApply(patternHole, tpt :: Nil), tpt2)
189189
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
190-
s.tpe <:< tpt.tpe &&
191-
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
192-
matched(scrutinee)
190+
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
191+
scrutinee match
192+
case Typed(s, tpt1) if s.tpe <:< tpt.tpe => matched(scrutinee)
193+
case _ => notMatched
193194

194195
/* Term hole */
195196
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
196-
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
197+
case TypeApply(patternHole, tpt :: Nil)
197198
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
198199
scrutinee.tpe <:< tpt.tpe =>
199-
matched(scrutinee)
200+
scrutinee match
201+
case ClosedPatternTerm(scrutinee) => matched(scrutinee)
202+
case _ => notMatched
203+
200204

201205
/* Higher order term hole */
202206
// Matches an open term and wraps it into a lambda that provides the free variables
203-
case (_, pattern @ Apply(TypeApply(Ident(_), List(TypeTree())), SeqLiteral(args, _) :: Nil))
207+
case Apply(TypeApply(Ident(_), List(TypeTree())), SeqLiteral(args, _) :: Nil)
204208
if pattern.symbol.eq(defn.QuotedRuntimePatterns_higherOrderHole) =>
205209
val names: List[TermName] = args.map {
206210
case Block(List(DefDef(nme.ANON_FUN, _, _, Apply(Ident(name), _))), _) => name.asTermName
@@ -221,12 +225,8 @@ object QuoteMatcher {
221225
}
222226
matched(Closure(meth, bodyFn))
223227

224-
//
225-
// Match two equivalent trees
226-
//
227-
228228
/* Match type ascription (b) */
229-
case (_, Typed(expr2, _)) =>
229+
case Typed(expr2, _) =>
230230
scrutinee =?= expr2
231231

232232
case _ =>

0 commit comments

Comments
 (0)