Skip to content

Constrain pattern types when typing a match type case #14563

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
Feb 28, 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
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val pat1 = withMode(Mode.Pattern) {
checkSimpleKinded(typedType(cdef.pat, mapPatternBounds = true))
}
if !ctx.isAfterTyper && pt != defn.ImplicitScrutineeTypeRef then
withMode(Mode.GadtConstraintInference) {
TypeComparer.constrainPatternType(pat1.tpe, selType)
}
val pat2 = indexPattern(cdef).transform(pat1)
var body1 = typedType(cdef.body, pt)
if !body1.isType then
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/i14151.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class BoundedPair[A, B <: A]:
type Second[A, T <: BoundedPair[A, _ <: A]] <: A = T match { case BoundedPair[A, b] => b }
2 changes: 2 additions & 0 deletions tests/pos/i14151b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Single[B](val value: B):
type Retrieve[A, T <: Single[_ <: A]] <: A = T match { case Single[b] => b }
2 changes: 2 additions & 0 deletions tests/pos/i14151c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Single[B](val value: B):
type Retrieve[A] <: A = Single[A] match { case Single[b] => b }