diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index c2367e6bfde0..fe06e90340a7 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -151,6 +151,7 @@ object TypeTestsCasts { case OrType(tp1, tp2) => recur(X, tp1) && recur(X, tp2) case AnnotatedType(t, _) => recur(X, t) case tp2: RefinedType => recur(X, tp2.parent) && TypeComparer.hasMatchingMember(tp2.refinedName, X, tp2) + case tp2: RecType => recur(X, tp2.parent) case _ => true }) diff --git a/tests/neg-custom-args/fatal-warnings/i11097.scala b/tests/neg-custom-args/fatal-warnings/i11097.scala new file mode 100644 index 000000000000..763babff81e2 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i11097.scala @@ -0,0 +1,13 @@ +@main def test: Unit = { + class C { type T1; type T2 } + + def pmatch(s: C): s.T2 = s match { + case p: (C { type T1 = Int; type T2 >: T1 } & s.type) => // error + (3: p.T1): p.T2 + case p: (C { type T1 = String; type T2 >: T1 } & s.type) => // error + ("this branch should be matched": p.T1): p.T2 + } + + // ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String + val x = pmatch(new C { type T1 = String; type T2 = String }) +} \ No newline at end of file