Skip to content

Commit

Permalink
Unify type parameters on quote pattern matching type lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Jul 31, 2023
1 parent 0a57531 commit 7bfa19d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ sealed trait GadtState {
finally if !result then restore(saved)
result

def unifySyms(params1: List[Symbol], params2: List[Symbol])(using Context) =
addToConstraint(params1)
addToConstraint(params2)
val paramrefs1 = params1 map (gadt.tvarOrError(_))
val paramrefs2 = params2 map (gadt.tvarOrError(_))
for ((p1, p2) <- paramrefs1.zip(paramrefs2))
do
addLess(p1.origin, p2.origin)
addLess(p2.origin, p1.origin)

// ---- Protected/internal -----------------------------------------------

override protected def constraint = gadt.constraint
Expand Down
20 changes: 16 additions & 4 deletions compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,25 @@ class QuoteMatcher(debug: Boolean) {
notMatched
case _ => matched

def matchTypeParams(ptparams: List[TypeDef], scparams: List[TypeDef]): optional[MatchingExprs] =
// TODO-18271: Compare type bounds
val ptsyms = ptparams.map(_.symbol)
val scsyms = scparams.map(_.symbol)
ctx.gadtState.unifySyms(ptsyms, scsyms)
matched

def matchParamss(scparamss: List[ParamClause], ptparamss: List[ParamClause])(using Env): optional[(Env, MatchingExprs)] =
(scparamss, ptparamss) match {
case (scparams :: screst, ptparams :: ptrest) =>
val mr1 = matchLists(scparams, ptparams)(_ =?= _)
val newEnv = summon[Env] ++ scparams.map(_.symbol).zip(ptparams.map(_.symbol))
val (resEnv, mrrest) = withEnv(newEnv)(matchParamss(screst, ptrest))
(resEnv, mr1 &&& mrrest)
(scparams, ptparams) match
case (TypeDefs(scparams), TypeDefs(ptparams)) =>
(summon[Env], matchTypeParams(scparams, ptparams))
case (ValDefs(scparams), ValDefs(ptparams)) =>
val mr1 = matchLists(scparams, ptparams)(_ =?= _)
val newEnv = summon[Env] ++ scparams.map(_.symbol).zip(ptparams.map(_.symbol))
val (resEnv, mrrest) = withEnv(newEnv)(matchParamss(screst, ptrest))
(resEnv, mr1 &&& mrrest)
case _ => notMatched
case (Nil, Nil) => (summon[Env], matched)
case _ => notMatched
}
Expand Down

0 comments on commit 7bfa19d

Please sign in to comment.