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 1 commit
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
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"