@@ -2,7 +2,7 @@ package dotty.tools
22package dotc
33package core
44
5- // import scala.language.{unsafeNulls => _}
5+ import scala .language .{unsafeNulls => _ }
66
77import Types ._ , Contexts ._ , Symbols ._ , Flags ._ , Names ._ , NameOps ._ , Denotations ._
88import Decorators ._
@@ -11,6 +11,7 @@ import StdNames.nme
1111import TypeOps .refineUsingParent
1212import collection .mutable
1313import util .Stats
14+ import util .NoSourcePosition
1415import config .Config
1516import config .Feature .migrateTo3
1617import config .Printers .{constr , subtyping , gadts , matchTypes , noPrinter }
@@ -38,9 +39,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
3839
3940 protected given [DummySoItsADef ]: Context = myContext
4041
41- protected var state : TyperState = null
42- def constraint : Constraint = state.constraint
43- def constraint_= (c : Constraint ): Unit = state.constraint = c
42+ protected var state : TyperState | Null = null
43+ def constraint : Constraint = state.nn. constraint
44+ def constraint_= (c : Constraint ): Unit = state.nn. constraint = c
4445
4546 def init (c : Context ): Unit =
4647 myContext = c
@@ -51,7 +52,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
5152 needsGc = false
5253 if Config .checkTypeComparerReset then checkReset()
5354
54- private var pendingSubTypes : util.MutableSet [(Type , Type )] = null
55+ private var pendingSubTypes : util.MutableSet [(Type , Type )] | Null = null
5556 private var recCount = 0
5657 private var monitored = false
5758
@@ -94,7 +95,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
9495
9596 override def checkReset () =
9697 super .checkReset()
97- assert(pendingSubTypes == null || pendingSubTypes.isEmpty)
98+ assert(pendingSubTypes == null || pendingSubTypes.uncheckedNN. isEmpty)
9899 assert(canCompareAtoms == true )
99100 assert(successCount == 0 )
100101 assert(totalCount == 0 )
@@ -153,7 +154,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
153154 * every time we compare components of the previous pair of types.
154155 * This type is used for capture conversion in `isSubArgs`.
155156 */
156- private [this ] var leftRoot : Type = null
157+ private [this ] var leftRoot : Type | Null = null
157158
158159 /** Are we forbidden from recording GADT constraints? */
159160 private var frozenGadt = false
@@ -222,7 +223,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
222223 def monitoredIsSubType = {
223224 if (pendingSubTypes == null ) {
224225 pendingSubTypes = util.HashSet [(Type , Type )]()
225- report.log(s " !!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}" )
226+ report.log(s " !!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.nn. constraint.show}" )
226227 report.log(s " !!! constraint = ${constraint.show}" )
227228 // if (ctx.settings.YnoDeepSubtypes.value) {
228229 // new Error("deep subtype").printStackTrace()
@@ -250,13 +251,13 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
250251 }
251252 }
252253 val p = (normalize(tp1), normalize(tp2))
253- ! pendingSubTypes.contains(p) && {
254+ ! pendingSubTypes.nn. contains(p) && {
254255 try {
255- pendingSubTypes += p
256+ pendingSubTypes.nn += p
256257 firstTry
257258 }
258259 finally
259- pendingSubTypes -= p
260+ pendingSubTypes.nn -= p
260261 }
261262 }
262263
@@ -392,7 +393,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
392393 thirdTry
393394 case tp1 : TypeParamRef =>
394395 def flagNothingBound = {
395- if (! frozenConstraint && isBottom(tp2) && state.isGlobalCommittable) {
396+ if (! frozenConstraint && isBottom(tp2) && state.nn. isGlobalCommittable) {
396397 def msg = s " !!! instantiated to Nothing: $tp1, constraint = ${constraint.show}"
397398 if (Config .failOnInstantiationToNothing) assert(false , msg)
398399 else report.log(msg)
@@ -1302,7 +1303,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
13021303 val saved = constraint
13031304 val savedGadt = ctx.gadt.fresh
13041305 inline def restore () =
1305- state.constraint = saved
1306+ state.nn. constraint = saved
13061307 ctx.gadt.restore(savedGadt)
13071308 val savedSuccessCount = successCount
13081309 try
@@ -1312,7 +1313,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
13121313 recCount -= 1
13131314 if ! result then restore()
13141315 else if recCount == 0 && needsGc then
1315- state.gc()
1316+ state.nn. gc()
13161317 needsGc = false
13171318 if (Stats .monitored) recordStatistics(result, savedSuccessCount)
13181319 result
@@ -1481,11 +1482,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
14811482 */
14821483 def compareCaptured (arg1 : TypeBounds , arg2 : Type ) = tparam match {
14831484 case tparam : Symbol =>
1484- if (leftRoot.isStable || ctx.isAfterTyper || ctx.mode.is(Mode .TypevarsMissContext ))
1485- && leftRoot.isValueType
1486- && leftRoot.member(tparam.name).exists
1485+ val leftr = leftRoot.nn
1486+ if (leftr.isStable || ctx.isAfterTyper || ctx.mode.is(Mode .TypevarsMissContext ))
1487+ && leftr.isValueType
1488+ && leftr.member(tparam.name).exists
14871489 then
1488- val captured = TypeRef (leftRoot , tparam)
1490+ val captured = TypeRef (leftr , tparam)
14891491 try isSubArg(captured, arg2)
14901492 catch case ex : TypeError =>
14911493 // The captured reference could be illegal and cause a
@@ -2458,7 +2460,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24582460 /** Does `tycon` have a field with type `tparam`? Special cased for `scala.*:`
24592461 * as that type is artificially added to tuples. */
24602462 private def typeparamCorrespondsToField (tycon : Type , tparam : TypeParamInfo ): Boolean =
2461- productSelectorTypes(tycon, null ).exists {
2463+ productSelectorTypes(tycon, NoSourcePosition ).exists {
24622464 case tp : TypeRef =>
24632465 tp.designator.eq(tparam) // Bingo!
24642466 case _ =>
@@ -2615,9 +2617,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
26152617 ! (tp2 <:< tp1)
26162618 && (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
26172619 case (tp1 : NamedType , _) if gadtBounds(tp1.symbol) != null =>
2618- provablyDisjoint(gadtBounds(tp1.symbol).hi, tp2) || provablyDisjoint(tp1.superType, tp2)
2620+ provablyDisjoint(gadtBounds(tp1.symbol).uncheckedNN. hi, tp2) || provablyDisjoint(tp1.superType, tp2)
26192621 case (_, tp2 : NamedType ) if gadtBounds(tp2.symbol) != null =>
2620- provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
2622+ provablyDisjoint(tp1, gadtBounds(tp2.symbol).uncheckedNN. hi) || provablyDisjoint(tp1, tp2.superType)
26212623 case (tp1 : TermRef , tp2 : TermRef ) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
26222624 tp1.termSymbol != tp2.termSymbol
26232625 case (tp1 : TermRef , tp2 : TypeRef ) if isEnumValue(tp1) =>
@@ -2669,12 +2671,12 @@ object TypeComparer {
26692671 }
26702672
26712673 private [core] def show (res : Any )(using Context ): String =
2672- if ctx.settings.YexplainLowlevel .value then String .valueOf(res)
2674+ if ctx.settings.YexplainLowlevel .value then String .valueOf(res).nn
26732675 else res match
26742676 case ClassInfo (_, cls, _, _, _) => cls.showLocated
26752677 case bounds : TypeBounds => i " type bounds [ $bounds] "
26762678 case res : printing.Showable => res.show
2677- case _ => String .valueOf(res)
2679+ case _ => String .valueOf(res).nn
26782680
26792681 /** The approximation state indicates how the pair of types currently compared
26802682 * relates to the types compared originally.
@@ -2828,7 +2830,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
28282830 super .addOneBound(param, bound, isUpper)
28292831 }
28302832
2831- override def gadtBounds (sym : Symbol )(using Context ): TypeBounds = {
2833+ override def gadtBounds (sym : Symbol )(using Context ): TypeBounds | Null = {
28322834 if (sym.exists) footprint += sym.typeRef
28332835 super .gadtBounds(sym)
28342836 }
0 commit comments