Skip to content

Commit 0e578f1

Browse files
committed
When assigning type cases, substitute any instances of type parameters for the applied arguments
1 parent 5a4a571 commit 0e578f1

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,19 @@ 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 params = getParams(new mutable.ListBuffer[TypeSymbol](), pat).toList
411+
pat.tpe match
412+
case AppliedType(tycon, args) =>
413+
val tparams = tycon.typeParamSymbols
414+
for param <- params do param.info = param.info.subst(tparams, args))
415+
case _ =>
416+
HKTypeLambda.fromParams(params, defn.MatchCase(pat.tpe, body.tpe))
413417
}
414418
else body.tpe
415419
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)