diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index ebaca5b626b1..a203584f27fe 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -116,7 +116,7 @@ object PatternMatcher { /** Widen type as far as necessary so that it does not refer to a pattern- * generated variable. */ - private def sanitize(tp: Type): Type = tp.widenExpr match { + private def sanitize(tp: Type): Type = tp.widenIfUnstable match { case tp: TermRef if refersToInternal(false, tp) => sanitize(tp.underlying) case tp => tp } diff --git a/tests/pos/i4999.scala b/tests/pos/i4999.scala new file mode 100644 index 000000000000..b7a856bf296a --- /dev/null +++ b/tests/pos/i4999.scala @@ -0,0 +1,9 @@ +trait Foo +final class Bar extends Foo + +class Test { + def test(xs: => Foo) = xs match { + case xs: Bar => 1 + case _ => 2 + } +}