Skip to content

Commit

Permalink
Use union of cases as default bound of match types
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBlanvillain committed Jan 29, 2020
1 parent 89a68b5 commit 7ae11ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,10 @@ class Typer extends Namer
val sel1 = typed(tree.selector)
val pt1 = if (bound1.isEmpty) pt else bound1.tpe
val cases1 = tree.cases.mapconserve(typedTypeCase(_, sel1.tpe, pt1))
assignType(cpy.MatchTypeTree(tree)(bound1, sel1, cases1), bound1, sel1, cases1)
val bound2 =
if (tree.bound.isEmpty) TypeTree(cases1.map(_.body.tpe).reduce(_ | _))
else bound1
assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1)
}

def typedByNameTypeTree(tree: untpd.ByNameTypeTree)(implicit ctx: Context): ByNameTypeTree = {
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i90.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test {
type F[X] = X match { case 10 => "0" case 11 => "1" }

implicitly[F[Any] <:< String]
}

0 comments on commit 7ae11ad

Please sign in to comment.