Skip to content

Commit 608a506

Browse files
committed
move admitsNull to Types.scala
1 parent b96d7e3 commit 608a506

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ object NullOpsDecorator:
5050
val stripped = self.stripNull()
5151
stripped ne self
5252
}
53-
54-
def admitsNull(using Context): Boolean = {
55-
self.isNullType || self.isAny || (self match
56-
case OrType(l, r) => r.admitsNull || l.admitsNull
57-
case AndType(l, r) => r.admitsNull && l.admitsNull
58-
case TypeBounds(lo, hi) => lo.admitsNull
59-
case FlexibleType(lo, hi) => true
60-
case tp: TypeProxy => tp.underlying.admitsNull
61-
case _ => false
62-
)
63-
}
6453
end extension
6554

6655
import ast.tpd.*

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ object Types extends TypeUtils {
382382
case _ => false
383383
}
384384

385+
/** Is it possible that `null` is a value of this type? */
386+
def admitsNull(using Context): Boolean =
387+
isNullType || isAny || (this match
388+
case OrType(l, r) => r.admitsNull || l.admitsNull
389+
case AndType(l, r) => r.admitsNull && l.admitsNull
390+
case TypeBounds(lo, hi) => lo.admitsNull
391+
case FlexibleType(lo, hi) => true
392+
case tp: TypeProxy => tp.underlying.admitsNull
393+
case _ => false
394+
)
395+
385396
/** Is this type produced as a repair for an error? */
386397
final def isError(using Context): Boolean = stripTypeVar.isInstanceOf[ErrorType]
387398

0 commit comments

Comments
 (0)