Skip to content

Commit 441afc5

Browse files
authored
Merge pull request #14645 from dwijnand/match-type/reduce-tparam-bounds-pr
2 parents 1baaa90 + 81cc6f1 commit 441afc5

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

tests/neg/6697.check

Lines changed: 0 additions & 13 deletions
This file was deleted.
File renamed without changes.

tests/pos/i14477.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sealed trait Foo[A, X <: A]
2+
3+
type FooX[F] = F match {
4+
case Foo[a, x] => x
5+
}
6+
7+
type MyFoo = Foo[String, "hello"]
8+
9+
val hello: FooX[MyFoo] = "hello"

0 commit comments

Comments
 (0)