Skip to content

Fix bounds of match type cases #14645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 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,25 @@ 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 params1 = getParams(new mutable.ListBuffer[TypeSymbol](), pat).toList
val params2 = pat.tpe match
case AppliedType(tycon, args) =>
val tparams = tycon.typeParamSymbols
params1.mapconserve { param =>
val info1 = param.info
val info2 = info1.subst(tparams, args)
if info2 eq info1 then param else param.copy(info = info2).asType
}
case _ => params1
val matchCase1 = defn.MatchCase(pat.tpe, body.tpe)
val matchCase2 = if params2 eq params1 then matchCase1 else matchCase1.substSym(params1, params2)
HKTypeLambda.fromParams(params2, matchCase2)
}
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"