Skip to content

Commit f009775

Browse files
committed
add comments for extractors
1 parent 2df913f commit f009775

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import dotty.tools.dotc.core.Types.{AndType, ClassInfo, ConstantType, OrType, Ty
88
object NullOpsDecorator {
99

1010
implicit class NullOps(val self: Type) {
11-
/** Is this type a reference to `Null`, possibly after aliasing? */
12-
def isNullType(implicit ctx: Context): Boolean = self.isRef(defn.NullClass)
13-
1411
/** Is this type exactly `JavaNull` (no vars, aliases, refinements etc allowed)? */
1512
def isJavaNullType(implicit ctx: Context): Boolean = {
1613
assert(ctx.explicitNulls)

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,9 +1445,7 @@ object Types {
14451445
}
14461446

14471447
/** Is this (an alias of) the `scala.Null` type? */
1448-
final def isNull(given Context) =
1449-
isRef(defn.NullClass)
1450-
|| classSymbol.name == tpnme.Null // !!! temporary kludge for being able to test without the explicit nulls PR
1448+
final def isNullType(given Context) = isRef(defn.NullClass)
14511449

14521450
/** The resultType of a LambdaType, or ExprType, the type itself for others */
14531451
def resultType(implicit ctx: Context): Type = this
@@ -2936,6 +2934,13 @@ object Types {
29362934
else apply(tp1, tp2)
29372935
}
29382936

2937+
/** An extractor object to pattern match against a nullable union.
2938+
* e.g.
2939+
*
2940+
* (tp: Type) match
2941+
* case OrNull(tp1) => // tp had the form `tp1 | Null`
2942+
* case _ => // tp was not a nullable union
2943+
*/
29392944
object OrNull {
29402945
def apply(tp: Type)(given Context) =
29412946
OrType(tp, defn.NullType)
@@ -2947,6 +2952,13 @@ object Types {
29472952
else None
29482953
}
29492954

2955+
/** An extractor object to pattern match against a Java-nullable union.
2956+
* e.g.
2957+
*
2958+
* (tp: Type) match
2959+
* case OrJavaNull(tp1) => // tp had the form `tp1 | JavaNull`
2960+
* case _ => // tp was not a Java-nullable union
2961+
*/
29502962
object OrJavaNull {
29512963
def apply(tp: Type)(given Context) =
29522964
OrType(tp, defn.JavaNullAliasType)

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ object Completion {
207207
def addMemberCompletions(qual: Tree)(implicit ctx: Context): Unit =
208208
if (!qual.tpe.widenDealias.isBottomType) {
209209
addAccessibleMembers(qual.tpe)
210-
if (!mode.is(Mode.Import) && !qual.tpe.isNull)
210+
if (!mode.is(Mode.Import) && !qual.tpe.isNullType)
211211
// Implicit conversions do not kick in when importing
212212
// and for `NullClass` they produce unapplicable completions (for unclear reasons)
213213
implicitConversionTargets(qual)(ctx.fresh.setExploreTyperState())

0 commit comments

Comments
 (0)