@@ -2,7 +2,7 @@ package dotty.tools
2
2
package dotc
3
3
package core
4
4
5
- // import scala.language.{unsafeNulls => _}
5
+ import scala .language .{unsafeNulls => _ }
6
6
7
7
import Types ._ , Contexts ._ , Symbols ._ , Flags ._ , Names ._ , NameOps ._ , Denotations ._
8
8
import Decorators ._
@@ -11,6 +11,7 @@ import StdNames.nme
11
11
import TypeOps .refineUsingParent
12
12
import collection .mutable
13
13
import util .Stats
14
+ import util .NoSourcePosition
14
15
import config .Config
15
16
import config .Feature .migrateTo3
16
17
import config .Printers .{constr , subtyping , gadts , matchTypes , noPrinter }
@@ -38,9 +39,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
38
39
39
40
protected given [DummySoItsADef ]: Context = myContext
40
41
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
44
45
45
46
def init (c : Context ): Unit =
46
47
myContext = c
@@ -51,7 +52,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
51
52
needsGc = false
52
53
if Config .checkTypeComparerReset then checkReset()
53
54
54
- private var pendingSubTypes : util.MutableSet [(Type , Type )] = null
55
+ private var pendingSubTypes : util.MutableSet [(Type , Type )] | Null = null
55
56
private var recCount = 0
56
57
private var monitored = false
57
58
@@ -94,7 +95,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
94
95
95
96
override def checkReset () =
96
97
super .checkReset()
97
- assert(pendingSubTypes == null || pendingSubTypes.isEmpty)
98
+ assert(pendingSubTypes == null || pendingSubTypes.uncheckedNN. isEmpty)
98
99
assert(canCompareAtoms == true )
99
100
assert(successCount == 0 )
100
101
assert(totalCount == 0 )
@@ -153,7 +154,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
153
154
* every time we compare components of the previous pair of types.
154
155
* This type is used for capture conversion in `isSubArgs`.
155
156
*/
156
- private [this ] var leftRoot : Type = null
157
+ private [this ] var leftRoot : Type | Null = null
157
158
158
159
/** Are we forbidden from recording GADT constraints? */
159
160
private var frozenGadt = false
@@ -222,7 +223,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
222
223
def monitoredIsSubType = {
223
224
if (pendingSubTypes == null ) {
224
225
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}" )
226
227
report.log(s " !!! constraint = ${constraint.show}" )
227
228
// if (ctx.settings.YnoDeepSubtypes.value) {
228
229
// new Error("deep subtype").printStackTrace()
@@ -250,13 +251,13 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
250
251
}
251
252
}
252
253
val p = (normalize(tp1), normalize(tp2))
253
- ! pendingSubTypes.contains(p) && {
254
+ ! pendingSubTypes.nn. contains(p) && {
254
255
try {
255
- pendingSubTypes += p
256
+ pendingSubTypes.nn += p
256
257
firstTry
257
258
}
258
259
finally
259
- pendingSubTypes -= p
260
+ pendingSubTypes.nn -= p
260
261
}
261
262
}
262
263
@@ -392,7 +393,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
392
393
thirdTry
393
394
case tp1 : TypeParamRef =>
394
395
def flagNothingBound = {
395
- if (! frozenConstraint && isBottom(tp2) && state.isGlobalCommittable) {
396
+ if (! frozenConstraint && isBottom(tp2) && state.nn. isGlobalCommittable) {
396
397
def msg = s " !!! instantiated to Nothing: $tp1, constraint = ${constraint.show}"
397
398
if (Config .failOnInstantiationToNothing) assert(false , msg)
398
399
else report.log(msg)
@@ -1302,7 +1303,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1302
1303
val saved = constraint
1303
1304
val savedGadt = ctx.gadt.fresh
1304
1305
inline def restore () =
1305
- state.constraint = saved
1306
+ state.nn. constraint = saved
1306
1307
ctx.gadt.restore(savedGadt)
1307
1308
val savedSuccessCount = successCount
1308
1309
try
@@ -1312,7 +1313,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1312
1313
recCount -= 1
1313
1314
if ! result then restore()
1314
1315
else if recCount == 0 && needsGc then
1315
- state.gc()
1316
+ state.nn. gc()
1316
1317
needsGc = false
1317
1318
if (Stats .monitored) recordStatistics(result, savedSuccessCount)
1318
1319
result
@@ -1481,11 +1482,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1481
1482
*/
1482
1483
def compareCaptured (arg1 : TypeBounds , arg2 : Type ) = tparam match {
1483
1484
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
1487
1489
then
1488
- val captured = TypeRef (leftRoot , tparam)
1490
+ val captured = TypeRef (leftr , tparam)
1489
1491
try isSubArg(captured, arg2)
1490
1492
catch case ex : TypeError =>
1491
1493
// The captured reference could be illegal and cause a
@@ -2458,7 +2460,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2458
2460
/** Does `tycon` have a field with type `tparam`? Special cased for `scala.*:`
2459
2461
* as that type is artificially added to tuples. */
2460
2462
private def typeparamCorrespondsToField (tycon : Type , tparam : TypeParamInfo ): Boolean =
2461
- productSelectorTypes(tycon, null ).exists {
2463
+ productSelectorTypes(tycon, NoSourcePosition ).exists {
2462
2464
case tp : TypeRef =>
2463
2465
tp.designator.eq(tparam) // Bingo!
2464
2466
case _ =>
@@ -2615,9 +2617,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2615
2617
! (tp2 <:< tp1)
2616
2618
&& (provablyDisjoint(tp1, tp2.tp2) || provablyDisjoint(tp1, tp2.tp1))
2617
2619
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)
2619
2621
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)
2621
2623
case (tp1 : TermRef , tp2 : TermRef ) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
2622
2624
tp1.termSymbol != tp2.termSymbol
2623
2625
case (tp1 : TermRef , tp2 : TypeRef ) if isEnumValue(tp1) =>
@@ -2669,12 +2671,12 @@ object TypeComparer {
2669
2671
}
2670
2672
2671
2673
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
2673
2675
else res match
2674
2676
case ClassInfo (_, cls, _, _, _) => cls.showLocated
2675
2677
case bounds : TypeBounds => i " type bounds [ $bounds] "
2676
2678
case res : printing.Showable => res.show
2677
- case _ => String .valueOf(res)
2679
+ case _ => String .valueOf(res).nn
2678
2680
2679
2681
/** The approximation state indicates how the pair of types currently compared
2680
2682
* relates to the types compared originally.
@@ -2828,7 +2830,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2828
2830
super .addOneBound(param, bound, isUpper)
2829
2831
}
2830
2832
2831
- override def gadtBounds (sym : Symbol )(using Context ): TypeBounds = {
2833
+ override def gadtBounds (sym : Symbol )(using Context ): TypeBounds | Null = {
2832
2834
if (sym.exists) footprint += sym.typeRef
2833
2835
super .gadtBounds(sym)
2834
2836
}
0 commit comments