Skip to content

Commit ee10fce

Browse files
Use union of cases as default bound of match types
1 parent 8dfa9a5 commit ee10fce

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,10 @@ class Typer extends Namer
14981498
val sel1 = typed(tree.selector)
14991499
val pt1 = if (bound1.isEmpty) pt else bound1.tpe
15001500
val cases1 = tree.cases.mapconserve(typedTypeCase(_, sel1.tpe, pt1))
1501-
assignType(cpy.MatchTypeTree(tree)(bound1, sel1, cases1), bound1, sel1, cases1)
1501+
val bound2 =
1502+
if (tree.bound.isEmpty) TypeTree(cases1.map(_.body.tpe).reduce(_ | _))
1503+
else bound1
1504+
assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1)
15021505
}
15031506

15041507
def typedByNameTypeTree(tree: untpd.ByNameTypeTree)(implicit ctx: Context): ByNameTypeTree = {

Diff for: tests/pos/i90.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
type F[X] = X match { case 10 => "0" case 11 => "1" }
3+
4+
implicitly[F[Any] <:< String]
5+
}

0 commit comments

Comments
 (0)