File tree Expand file tree Collapse file tree 6 files changed +13
-12
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 6 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
5757 def unitLiteral (implicit ctx : Context ): Literal =
5858 Literal (Constant (()))
5959
60+ def nullLiteral (implicit ctx : Context ): Literal =
61+ Literal (Constant (null ))
62+
6063 def New (tpt : Tree )(implicit ctx : Context ): New =
6164 ta.assignType(untpd.New (tpt), tpt)
6265
@@ -496,7 +499,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
496499 else if (tpw isRef defn.DoubleClass ) Literal (Constant (0d ))
497500 else if (tpw isRef defn.ByteClass ) Literal (Constant (0 .toByte))
498501 else if (tpw isRef defn.ShortClass ) Literal (Constant (0 .toShort))
499- else Literal ( Constant ( null )) .select(defn.Any_asInstanceOf ).appliedToType(tpe)
502+ else nullLiteral .select(defn.Any_asInstanceOf ).appliedToType(tpe)
500503 }
501504
502505 private class FindLocalDummyAccumulator (cls : ClassSymbol )(implicit ctx : Context ) extends TreeAccumulator [Symbol ] {
@@ -915,7 +918,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
915918 Typed (tree, TypeTree (defn.AnyRefType ))
916919 }
917920 else tree.ensureConforms(defn.ObjectType )
918- receiver.select(defn.Object_ne ).appliedTo(Literal ( Constant ( null )) )
921+ receiver.select(defn.Object_ne ).appliedTo(nullLiteral )
919922 }
920923
921924 /** If inititializer tree is `_', the default value of its type,
Original file line number Diff line number Diff line change @@ -235,7 +235,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
235235 else {
236236 // insert test: if ($outer eq null) throw new NullPointerException
237237 val nullTest =
238- If (ref(param).select(defn.Object_eq ).appliedTo(Literal ( Constant ( null )) ),
238+ If (ref(param).select(defn.Object_eq ).appliedTo(nullLiteral ),
239239 Throw (New (defn.NullPointerExceptionClass .typeRef, Nil )),
240240 unitLiteral)
241241 nullTest :: assigns
Original file line number Diff line number Diff line change @@ -218,7 +218,7 @@ object Erasure {
218218 adaptToType(tree, underlying)
219219 else if (! (tree.tpe <:< tycon)) {
220220 assert(! (tree.tpe.typeSymbol.isPrimitiveValueClass))
221- val nullTree = Literal ( Constant ( null ))
221+ val nullTree = nullLiteral
222222 val unboxedNull = adaptToType(nullTree, underlying)
223223
224224 evalOnce(tree) { t =>
Original file line number Diff line number Diff line change @@ -189,14 +189,12 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
189189 holders::: stats
190190 }
191191
192- private def nullOut (nullables : List [Symbol ])(implicit ctx : Context ): List [Tree ] = {
193- val nullConst = Literal (Constant (null ))
192+ private def nullOut (nullables : List [Symbol ])(implicit ctx : Context ): List [Tree ] =
194193 nullables.map { field =>
195194 assert(field.isField)
196195 field.setFlag(Mutable )
197- ref(field).becomes(nullConst )
196+ ref(field).becomes(nullLiteral )
198197 }
199- }
200198
201199 /** Create non-threadsafe lazy accessor equivalent to such code
202200 * ```
@@ -237,7 +235,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
237235 val targetRef = ref(target)
238236 val stats = targetRef.becomes(rhs) :: nullOut(nullableFor(sym))
239237 val init = If (
240- targetRef.select(nme.eq).appliedTo(Literal ( Constant ( null )) ),
238+ targetRef.select(nme.eq).appliedTo(nullLiteral ),
241239 Block (stats.init, stats.last),
242240 unitLiteral
243241 )
Original file line number Diff line number Diff line change @@ -106,8 +106,8 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
106106 val NoFieldNeeded = Lazy | Deferred | JavaDefined | (if (ctx.settings.YnoInline .value) EmptyFlags else Inline )
107107
108108 def erasedBottomTree (sym : Symbol ) = {
109- if (sym eq defn.NothingClass ) Throw (Literal ( Constant ( null )) )
110- else if (sym eq defn.NullClass ) Literal ( Constant ( null ))
109+ if (sym eq defn.NothingClass ) Throw (nullLiteral )
110+ else if (sym eq defn.NullClass ) nullLiteral
111111 else if (sym eq defn.BoxedUnitClass ) ref(defn.BoxedUnit_UNIT )
112112 else {
113113 assert(false , sym + " has no erased bottom tree" )
Original file line number Diff line number Diff line change @@ -361,7 +361,7 @@ object PatternMatcher {
361361 val unappPlan = if (defn.isBottomType(scrutinee.info)) {
362362 // Generate a throwaway but type-correct plan.
363363 // This plan will never execute because it'll be guarded by a `NonNullTest`.
364- ResultPlan (tpd.Throw (tpd.Literal ( Constant ( null )) ))
364+ ResultPlan (tpd.Throw (tpd.nullLiteral ))
365365 } else {
366366 val mt @ MethodType (_) = extractor.tpe.widen
367367 var unapp = extractor.appliedTo(ref(scrutinee).ensureConforms(mt.paramInfos.head))
You can’t perform that action at this time.
0 commit comments