Skip to content

Commit

Permalink
When assigning type cases, substitute any instances of type parameter…
Browse files Browse the repository at this point in the history
…s for the applied arguments
  • Loading branch information
dwijnand committed Mar 8, 2022
1 parent 5a4a571 commit 0e578f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,19 @@ trait TypeAssigner {
def assignType(tree: untpd.CaseDef, pat: Tree, body: Tree)(using Context): CaseDef = {
val ownType =
if (body.isType) {
val params = new TreeAccumulator[mutable.ListBuffer[TypeSymbol]] {
val getParams = new TreeAccumulator[mutable.ListBuffer[TypeSymbol]] {
def apply(ps: mutable.ListBuffer[TypeSymbol], t: Tree)(using Context) = t match {
case t: Bind if t.symbol.isType => foldOver(ps += t.symbol.asType, t)
case _ => foldOver(ps, t)
}
}
HKTypeLambda.fromParams(
params(new mutable.ListBuffer[TypeSymbol](), pat).toList,
defn.MatchCase(pat.tpe, body.tpe))
val params = getParams(new mutable.ListBuffer[TypeSymbol](), pat).toList
pat.tpe match
case AppliedType(tycon, args) =>
val tparams = tycon.typeParamSymbols
for param <- params do param.info = param.info.subst(tparams, args))
case _ =>
HKTypeLambda.fromParams(params, defn.MatchCase(pat.tpe, body.tpe))
}
else body.tpe
tree.withType(ownType)
Expand Down
13 changes: 0 additions & 13 deletions tests/neg/6697.check

This file was deleted.

File renamed without changes.
9 changes: 9 additions & 0 deletions tests/pos/i14477.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sealed trait Foo[A, X <: A]

type FooX[F] = F match {
case Foo[a, x] => x
}

type MyFoo = Foo[String, "hello"]

val hello: FooX[MyFoo] = "hello"

0 comments on commit 0e578f1

Please sign in to comment.