@@ -401,15 +401,25 @@ trait TypeAssigner {
401401 def assignType (tree : untpd.CaseDef , pat : Tree , body : Tree )(using Context ): CaseDef = {
402402 val ownType =
403403 if (body.isType) {
404- val params = new TreeAccumulator [mutable.ListBuffer [TypeSymbol ]] {
404+ val getParams = new TreeAccumulator [mutable.ListBuffer [TypeSymbol ]] {
405405 def apply (ps : mutable.ListBuffer [TypeSymbol ], t : Tree )(using Context ) = t match {
406406 case t : Bind if t.symbol.isType => foldOver(ps += t.symbol.asType, t)
407407 case _ => foldOver(ps, t)
408408 }
409409 }
410- HKTypeLambda .fromParams(
411- params(new mutable.ListBuffer [TypeSymbol ](), pat).toList,
412- defn.MatchCase (pat.tpe, body.tpe))
410+ val params1 = getParams(new mutable.ListBuffer [TypeSymbol ](), pat).toList
411+ val params2 = pat.tpe match
412+ case AppliedType (tycon, args) =>
413+ val tparams = tycon.typeParamSymbols
414+ params1.mapconserve { param =>
415+ val info1 = param.info
416+ val info2 = info1.subst(tparams, args)
417+ if info2 eq info1 then param else param.copy(info = info2).asType
418+ }
419+ case _ => params1
420+ val matchCase1 = defn.MatchCase (pat.tpe, body.tpe)
421+ val matchCase2 = if params2 eq params1 then matchCase1 else matchCase1.substSym(params1, params2)
422+ HKTypeLambda .fromParams(params2, matchCase2)
413423 }
414424 else body.tpe
415425 tree.withType(ownType)
0 commit comments