Skip to content

Commit e96a1be

Browse files
committed
Fail fast for hole pattterns
1 parent 95fad60 commit e96a1be

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
@@ -185,26 +185,30 @@ object QuoteMatcher {
185185
case _ => None
186186
end TypeTreeTypeTest
187187

188-
val res = (scrutinee, pattern) match
188+
val res = pattern match
189189

190190
/* Term hole */
191191
// Match a scala.internal.Quoted.patternHole typed as a repeated argument and return the scrutinee tree
192-
case (Typed(s, tpt1), Typed(TypeApply(patternHole, tpt :: Nil), tpt2))
192+
case Typed(TypeApply(patternHole, tpt :: Nil), tpt2)
193193
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
194-
s.tpe <:< tpt.tpe &&
195-
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
196-
matched(scrutinee)
194+
tpt2.tpe.derivesFrom(defn.RepeatedParamClass) =>
195+
scrutinee match
196+
case Typed(s, tpt1) if s.tpe <:< tpt.tpe => matched(scrutinee)
197+
case _ => notMatched
197198

198199
/* Term hole */
199200
// Match a scala.internal.Quoted.patternHole and return the scrutinee tree
200-
case (ClosedPatternTerm(scrutinee), TypeApply(patternHole, tpt :: Nil))
201+
case TypeApply(patternHole, tpt :: Nil)
201202
if patternHole.symbol.eq(defn.QuotedRuntimePatterns_patternHole) &&
202203
scrutinee.tpe <:< tpt.tpe =>
203-
matched(scrutinee)
204+
scrutinee match
205+
case ClosedPatternTerm(scrutinee) => matched(scrutinee)
206+
case _ => notMatched
207+
204208

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

228-
//
229-
// Match two equivalent trees
230-
//
231-
232232
/* Match type ascription (b) */
233-
case (_, Typed(expr2, _)) =>
233+
case Typed(expr2, _) =>
234234
scrutinee =?= expr2
235235

236236
case _ =>

0 commit comments

Comments
 (0)