Skip to content

Commit d0a9c47

Browse files
committed
Fix #17435: A simpler fix
1 parent 830230f commit d0a9c47

File tree

1 file changed

+4
-52
lines changed

1 file changed

+4
-52
lines changed

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ object TypeTestsCasts {
5353
* 6. if `P = T1 | T2` or `P = T1 & T2`, checkable(X, T1) && checkable(X, T2).
5454
* 7. if `P` is a refinement type, "it's a refinement type"
5555
* 8. if `P` is a local class which is not statically reachable from the scope where `X` is defined, "it's a local class"
56-
* 9. if `X` is `T1 | T2`, checkable(T1, P) && checkable(T2, P) or (isCheckDefinitelyFalse(T1, P) && checkable(T2, P)) or (checkable(T1, P) && isCheckDefinitelyFalse(T2, P)).
56+
* 9. if `X` is `T1 | T2`, checkable(T1, P) && checkable(T2, P).
5757
* 10. otherwise, ""
5858
*/
5959
def whyUncheckable(X: Type, P: Type, span: Span)(using Context): String = atPhase(Phases.refchecksPhase.next) {
@@ -132,41 +132,6 @@ object TypeTestsCasts {
132132

133133
}
134134

135-
/** Whether the check X.isInstanceOf[P] is definitely false? */
136-
def isCheckDefinitelyFalse(X: Type, P: Type)(using Context): Boolean = trace(s"isCheckDefinitelyFalse(${X.show}, ${P.show})") {
137-
X.widenDealias match
138-
case AndType(x1, x2) =>
139-
isCheckDefinitelyFalse(x1, P) || isCheckDefinitelyFalse(x2, P)
140-
141-
case x =>
142-
P.widenDealias match
143-
case AndType(p1, p2) =>
144-
isCheckDefinitelyFalse(x, p1) || isCheckDefinitelyFalse(x, p2)
145-
146-
case p =>
147-
val pSpace = Typ(p)
148-
val xSpace = Typ(x)
149-
if pSpace.canDecompose then
150-
val ps = pSpace.decompose.map(_.tp)
151-
ps.forall(p => isCheckDefinitelyFalse(x, p))
152-
else if xSpace.canDecompose then
153-
val xs = xSpace.decompose.map(_.tp)
154-
xs.forall(x => isCheckDefinitelyFalse(x, p))
155-
else
156-
if x.typeSymbol.isClass && p.typeSymbol.isClass then
157-
val xClass = effectiveClass(x)
158-
val pClass = effectiveClass(p)
159-
160-
val bothAreClasses = !xClass.is(Trait) && !pClass.is(Trait)
161-
val notXsubP = !xClass.derivesFrom(pClass)
162-
val notPsubX = !pClass.derivesFrom(xClass)
163-
bothAreClasses && notXsubP && notPsubX
164-
|| xClass.is(Final) && notXsubP
165-
|| pClass.is(Final) && notPsubX
166-
else
167-
false
168-
}
169-
170135
def recur(X: Type, P: Type): String = (X <:< P) ||| (P.dealias match {
171136
case _: SingletonType => ""
172137
case _: TypeProxy
@@ -184,24 +149,11 @@ object TypeTestsCasts {
184149
// - T1 <:< T2 | T3
185150
// - T1 & T2 <:< T3
186151
// See TypeComparer#either
187-
val res1 = recur(tp1, P)
188-
val res2 = recur(tp2, P)
189-
190-
if res1.isEmpty && res2.isEmpty then
191-
res1
192-
else if res2.isEmpty then
193-
if isCheckDefinitelyFalse(tp1, P) then res2
194-
else res1
195-
else if res1.isEmpty then
196-
if isCheckDefinitelyFalse(tp2, P) then res1
197-
else res2
198-
else
199-
res1
152+
recur(tp1, P) && recur(tp2, P)
200153

201-
case _ =>
154+
case x =>
202155
// always false test warnings are emitted elsewhere
203-
X.classSymbol.exists && P.classSymbol.exists &&
204-
!X.classSymbol.asClass.mayHaveCommonChild(P.classSymbol.asClass)
156+
TypeComparer.provablyDisjoint(x, tpe)
205157
|| typeArgsTrivial(X, tpe)
206158
||| i"its type arguments can't be determined from $X"
207159
}

0 commit comments

Comments
 (0)