File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
compiler/src/dotty/tools/dotc
tests/pos-special/fatal-warnings Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1575,6 +1575,17 @@ object SymDenotations {
15751575 (symbol eq defn.NothingClass ) ||
15761576 (symbol eq defn.NullClass ) && (base ne defn.NothingClass ))
15771577
1578+ /** Is it possible that a class inherits both `this` and `that`?
1579+ *
1580+ * @note The test is based on single-class inheritance and the closed
1581+ * hierarchy of final classes.
1582+ *
1583+ * @return The result may contain false positives, but never false negatives.
1584+ */
1585+ final def mayHaveCommonChild (that : ClassSymbol )(implicit ctx : Context ): Boolean =
1586+ ! this .is(Final ) && ! that.is(Final ) && (this .is(Trait ) || that.is(Trait )) ||
1587+ this .derivesFrom(that) || that.derivesFrom(this .symbol)
1588+
15781589 final override def typeParamCreationFlags : FlagSet = ClassTypeParamCreationFlags
15791590
15801591 /** Hook to do a pre-enter test. Overridden in PackageDenotation */
Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ object TypeTestsCasts {
132132 recur(tp1, P ) && recur(tp2, P )
133133 case _ =>
134134 // first try withou striping type parameters for performance
135+ ! X .classSymbol.asClass.mayHaveCommonChild(P .classSymbol.asClass) ||
135136 isClassDetermined(X , tpe)(ctx.fresh.setNewTyperState()) ||
136137 isClassDetermined(stripTypeParam(X ), tpe)(ctx.fresh.setNewTyperState())
137138 }
Original file line number Diff line number Diff line change 1+ object Test extends App {
2+ case class Foo [T ](t : T )
3+
4+ def foo [T ](ft : Unit | Foo [T ]): T = {
5+ ft match {
6+ case Foo (t) => t
7+ case () => ???
8+ }
9+ }
10+
11+ foo(Foo (23 ))
12+ }
You can’t perform that action at this time.
0 commit comments