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 @@ -1571,6 +1571,17 @@ object SymDenotations {
15711571 (symbol eq defn.NothingClass ) ||
15721572 (symbol eq defn.NullClass ) && (base ne defn.NothingClass ))
15731573
1574+ /** Is it possible that a class inherits both `this` and `that`?
1575+ *
1576+ * @note The test is based on single-class inheritance and the closed
1577+ * hierarchy of final classes.
1578+ *
1579+ * @return The result may contain false positives, but never false negatives.
1580+ */
1581+ final def mayHaveCommonChild (that : ClassSymbol )(implicit ctx : Context ): Boolean =
1582+ ! this .is(Final ) && ! that.is(Final ) && (this .is(Trait ) || that.is(Trait )) ||
1583+ this .derivesFrom(that) || that.derivesFrom(this .symbol)
1584+
15741585 final override def typeParamCreationFlags : FlagSet = ClassTypeParamCreationFlags
15751586
15761587 /** 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.exists && P .classSymbol.exists && ! 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