Skip to content

Commit e36c28d

Browse files
committed
Make pattern match against method parameters consider dependency
1 parent 6e54f7f commit e36c28d

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

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

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -364,20 +364,22 @@ object QuoteMatcher {
364364
case scrutinee @ DefDef(_, paramss1, tpt1, _) =>
365365
pattern match
366366
case pattern @ DefDef(_, paramss2, tpt2, _) =>
367-
// TODO 17105: "rhs" is no longer appropriate, let's rename...
368-
def defEnv: Env =
369-
val paramSyms: List[(Symbol, Symbol)] =
370-
for
371-
(clause1, clause2) <- paramss1.zip(paramss2)
372-
(param1, param2) <- clause1.zip(clause2)
373-
yield
374-
param1.symbol -> param2.symbol
375-
val oldEnv: Env = summon[Env]
376-
val newEnv: List[(Symbol, Symbol)] = (scrutinee.symbol -> pattern.symbol) :: paramSyms
377-
oldEnv ++ newEnv
378-
matchLists(paramss1, paramss2)(_ =?= _)
379-
&&& withEnv(defEnv)(tpt1 =?= tpt2)
380-
&&& withEnv(defEnv)(scrutinee.rhs =?= pattern.rhs)
367+
def matchParamss(scparamss: List[ParamClause], ptparamss: List[ParamClause])(using Env): optional[(Env, MatchingExprs)] =
368+
(scparamss, ptparamss) match {
369+
case (scparams :: screst, ptparams :: ptrest) =>
370+
val mr1 = matchLists(scparams, ptparams)(_ =?= _)
371+
val newEnv = summon[Env] ++ scparams.map(_.symbol).zip(ptparams.map(_.symbol))
372+
val (resEnv, mrrest) = withEnv(newEnv)(matchParamss(screst, ptrest))
373+
(resEnv, mr1 &&& mrrest)
374+
case (Nil, Nil) => (summon[Env], matched)
375+
case _ => notMatched
376+
}
377+
378+
val (pEnv, pmatch) = matchParamss(paramss1, paramss2)
379+
val defEnv = pEnv + (scrutinee.symbol -> pattern.symbol)
380+
pmatch
381+
&&& withEnv(defEnv)(tpt1 =?= tpt2)
382+
&&& withEnv(defEnv)(scrutinee.rhs =?= pattern.rhs)
381383
case _ => notMatched
382384

383385
case Closure(_, _, tpt1) =>
@@ -398,22 +400,6 @@ object QuoteMatcher {
398400
case _ =>
399401
notMatched
400402

401-
if (debug && res == notMatched)
402-
val quotes = QuotesImpl()
403-
println(
404-
s""">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
405-
|Scrutinee
406-
| ${scrutinee.show}
407-
|did not match pattern
408-
| ${pattern.show}
409-
|
410-
|with environment: ${summon[Env]}
411-
|
412-
|Scrutinee: ${quotes.reflect.Printer.TreeStructure.show(scrutinee.asInstanceOf)}
413-
|Pattern: ${quotes.reflect.Printer.TreeStructure.show(pattern.asInstanceOf)}
414-
|
415-
|""".stripMargin)
416-
417403
res
418404
end =?=
419405

@@ -546,7 +532,7 @@ object QuoteMatcher {
546532
val hoasClosure = Closure(meth, bodyFn)
547533
new ExprImpl(hoasClosure, spliceScope)
548534

549-
private inline def notMatched: optional[MatchingExprs] =
535+
private inline def notMatched[T]: optional[T] =
550536
optional.break()
551537

552538
private inline def matched: MatchingExprs =

0 commit comments

Comments
 (0)