From 51be5b89bcafcb03589b90f6c578c32222646b8f Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 22 Sep 2025 19:17:04 +0200 Subject: [PATCH] Make isExactlyNothing and isExactlyAny work for And/OrTypes Might fix #24013. [Cherry-picked 2fa9003a9747ced5661dc8159f88163ac1de5b31] --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index abdf7c82bbfd..54bfeaadb179 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -243,6 +243,10 @@ object Types extends TypeUtils { def isExactlyNothing(using Context): Boolean = this match { case tp: TypeRef => tp.name == tpnme.Nothing && (tp.symbol eq defn.NothingClass) + case AndType(tp1, tp2) => + tp1.isExactlyNothing || tp2.isExactlyNothing + case OrType(tp1, tp2) => + tp1.isExactlyNothing && tp2.isExactlyNothing case _ => false } @@ -250,6 +254,10 @@ object Types extends TypeUtils { def isExactlyAny(using Context): Boolean = this match { case tp: TypeRef => tp.name == tpnme.Any && (tp.symbol eq defn.AnyClass) + case AndType(tp1, tp2) => + tp1.isExactlyAny && tp2.isExactlyAny + case OrType(tp1, tp2) => + tp1.isExactlyAny || tp2.isExactlyAny case _ => false }