File tree 3 files changed +24
-0
lines changed
compiler/src/dotty/tools/dotc
tests/pos-special/fatal-warnings
3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1575,6 +1575,17 @@ object SymDenotations {
1575
1575
(symbol eq defn.NothingClass ) ||
1576
1576
(symbol eq defn.NullClass ) && (base ne defn.NothingClass ))
1577
1577
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
+
1578
1589
final override def typeParamCreationFlags : FlagSet = ClassTypeParamCreationFlags
1579
1590
1580
1591
/** 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 {
132
132
recur(tp1, P ) && recur(tp2, P )
133
133
case _ =>
134
134
// first try withou striping type parameters for performance
135
+ ! X .classSymbol.asClass.mayHaveCommonChild(P .classSymbol.asClass) ||
135
136
isClassDetermined(X , tpe)(ctx.fresh.setNewTyperState()) ||
136
137
isClassDetermined(stripTypeParam(X ), tpe)(ctx.fresh.setNewTyperState())
137
138
}
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