From e4cb7b8a75a78b13347cee226f747a13f9fcfcc9 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 3 Oct 2022 14:58:22 +0200 Subject: [PATCH] Type match with a match type when a match type is expected --- .../src/dotty/tools/dotc/typer/Typer.scala | 2 ++ tests/pos/match-type-inference.scala | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/pos/match-type-inference.scala 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