Skip to content

Type match with a match type when a match type is expected #15599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
Expand Down
22 changes: 22 additions & 0 deletions tests/pos/match-type-inference.scala
Original file line number Diff line number Diff line change
@@ -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