diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 6a1e6e0b671f..580c9f71ad29 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1609,6 +1609,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer } val result = pt match { + case mt: MatchType if isMatchTypeShaped(mt) => + typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt) case MatchType.InDisguise(mt) if isMatchTypeShaped(mt) => typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt) case _ => diff --git a/tests/pos/match-type-inference.scala b/tests/pos/match-type-inference.scala new file mode 100644 index 000000000000..4105e788c207 --- /dev/null +++ b/tests/pos/match-type-inference.scala @@ -0,0 +1,22 @@ +type IsString[T <: Any] = T match { + case String => true + case _ => false +} + +def isString(x: Any): IsString[x.type] = x match + case _: String => true + case _ => false + +def isString2(x: Any): x.type match { + case String => true + case _ => false +} = x match + case _: String => true + case _ => false + +def isString3[T](x: T): T match { + case String => true + case _ => false +} = x match + case _: String => true + case _ => false