Skip to content

Commit c574f31

Browse files
authored
Type match with a match type when a match type is expected (#15599)
2 parents bfa32a4 + e4cb7b8 commit c574f31

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16091609
}
16101610

16111611
val result = pt match {
1612+
case mt: MatchType if isMatchTypeShaped(mt) =>
1613+
typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt)
16121614
case MatchType.InDisguise(mt) if isMatchTypeShaped(mt) =>
16131615
typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt)
16141616
case _ =>

tests/pos/match-type-inference.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type IsString[T <: Any] = T match {
2+
case String => true
3+
case _ => false
4+
}
5+
6+
def isString(x: Any): IsString[x.type] = x match
7+
case _: String => true
8+
case _ => false
9+
10+
def isString2(x: Any): x.type match {
11+
case String => true
12+
case _ => false
13+
} = x match
14+
case _: String => true
15+
case _ => false
16+
17+
def isString3[T](x: T): T match {
18+
case String => true
19+
case _ => false
20+
} = x match
21+
case _: String => true
22+
case _ => false

0 commit comments

Comments
 (0)