diff --git a/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala b/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala index d0f9a49cf216..c20b2868726a 100644 --- a/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala +++ b/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala @@ -140,8 +140,8 @@ trait PatternTypeConstrainer { self: TypeComparer => either(constrainPatternType(pat1, scrut), constrainPatternType(pat2, scrut)) case AndType(pat1, pat2) => constrainPatternType(pat1, scrut) && constrainPatternType(pat2, scrut) - case scrut: RefinedOrRecType => - constrainPatternType(stripRefinement(scrut), pat) + case pat: RefinedOrRecType => + constrainPatternType(stripRefinement(pat), scrut) case pat => constrainSimplePatternType(pat, scrut) || classesMayBeCompatible && constrainUpcasted(scrut) } diff --git a/tests/pos/gadt-strip-refinement.scala b/tests/pos/gadt-strip-refinement.scala new file mode 100644 index 000000000000..6e794322d6c9 --- /dev/null +++ b/tests/pos/gadt-strip-refinement.scala @@ -0,0 +1,6 @@ +trait Tag[T] { type X } +class IntTag extends Tag[Int] + +def foo[T](x: Tag[T]): T = x match { + case _: IntTag { type X = String } => 0 +}