diff --git a/compiler/src/dotty/tools/dotc/CompilationUnit.scala b/compiler/src/dotty/tools/dotc/CompilationUnit.scala index a6069e2749a9..01d8278af1f4 100644 --- a/compiler/src/dotty/tools/dotc/CompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/CompilationUnit.scala @@ -71,7 +71,7 @@ class CompilationUnit protected (val source: SourceFile) { suspendedAtInliningPhase = true throw CompilationUnit.SuspendException() - private var myAssignmentSpans: Map[Int, List[Span]] | Null = null + private var myAssignmentSpans: Map[Int, List[Span]] | Uninitialized = initiallyNull /** A map from (name-) offsets of all local variables in this compilation unit * that can be tracked for being not null to the list of spans of assignments diff --git a/compiler/src/dotty/tools/dotc/ast/Positioned.scala b/compiler/src/dotty/tools/dotc/ast/Positioned.scala index 4de57def853e..143862905e64 100644 --- a/compiler/src/dotty/tools/dotc/ast/Positioned.scala +++ b/compiler/src/dotty/tools/dotc/ast/Positioned.scala @@ -160,7 +160,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src */ def checkPos(nonOverlapping: Boolean)(using Context): Unit = try { import untpd._ - var lastPositioned: Positioned | Null = null + var lastPositioned: Positioned | Uninitialized = initiallyNull var lastSpan = NoSpan def check(p: Any): Unit = p match { case p: Positioned => @@ -234,7 +234,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src object Positioned { @sharable private var debugId = Int.MinValue - @sharable private var ids: java.util.WeakHashMap[Positioned, Int] | Null = null + @sharable private var ids: java.util.WeakHashMap[Positioned, Int] | Uninitialized = initiallyNull @sharable private var nextId: Int = 0 def init(using Context): Unit = diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index c155f42c52e6..48e6d1a73a98 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -294,7 +294,7 @@ object Trees { trait DefTree[-T >: Untyped] extends DenotingTree[T] { type ThisTree[-T >: Untyped] <: DefTree[T] - private var myMods: untpd.Modifiers | Null = _ + private var myMods: untpd.Modifiers | Uninitialized = _ private[dotc] def rawMods: untpd.Modifiers = if (myMods == null) untpd.EmptyModifiers else myMods.uncheckedNN diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 2e87194ff207..9bc8060703e0 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -1256,7 +1256,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { trait TreeProvider { protected def computeRootTrees(using Context): List[Tree] - private var myTrees: List[Tree] | Null = _ + private var myTrees: List[Tree] | Uninitialized = _ /** Get trees defined by this provider. Cache them if -Yretain-trees is set. */ def rootTrees(using Context): List[Tree] = diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index a185ad252073..30eb135f5008 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -163,7 +163,7 @@ object Names { override def asTermName: TermName = this @sharable // because it is only modified in the synchronized block of toTypeName. - private var myTypeName: TypeName | Null = null + private var myTypeName: TypeName | Uninitialized = initiallyNull // Note: no @volatile needed since type names are immutable and therefore safely published override def toTypeName: TypeName = @@ -225,10 +225,10 @@ object Names { } @sharable // because it's just a cache for performance - private var myMangledString: String | Null = null + private var myMangledString: String | Uninitialized = initiallyNull @sharable // because it's just a cache for performance - private var myMangled: Name | Null = null + private var myMangled: Name | Uninitialized = initiallyNull protected[Names] def mangle: ThisName @@ -259,7 +259,7 @@ object Names { protected def computeToString: String - @sharable private var myToString: String | Null = null + @sharable private var myToString: String | Uninitialized = initiallyNull override def toString: String = if myToString == null then myToString = computeToString diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index 675816ad200f..75e742e1cd86 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -565,7 +565,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, i += 1 } - private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Null = _ + private var myUninstVars: mutable.ArrayBuffer[TypeVar] | Uninitialized = _ /** The uninstantiated typevars of this constraint */ def uninstVars: collection.Seq[TypeVar] = { diff --git a/compiler/src/dotty/tools/dotc/core/Scopes.scala b/compiler/src/dotty/tools/dotc/core/Scopes.scala index 863ae4fa6b7f..bd3ca54f7f68 100644 --- a/compiler/src/dotty/tools/dotc/core/Scopes.scala +++ b/compiler/src/dotty/tools/dotc/core/Scopes.scala @@ -213,14 +213,14 @@ object Scopes { /** the hash table */ - private var hashTable: Array[ScopeEntry | Null] | Null = null + private var hashTable: Array[ScopeEntry | Null] | Uninitialized = initiallyNull /** a cache for all elements, to be used by symbol iterator. */ private var elemsCache: List[Symbol] | Null = null /** The synthesizer to be used, or `null` if no synthesis is done on this scope */ - private var synthesize: SymbolSynthesizer | Null = null + private var synthesize: SymbolSynthesizer | Uninitialized = initiallyNull /** Use specified synthesize for this scope */ def useSynthesizer(s: SymbolSynthesizer): Unit = synthesize = s diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index e1a54325af03..f9df023550d0 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -495,7 +495,7 @@ object SymDenotations { /** `fullName` where `.' is the separator character */ def fullName(using Context): Name = fullNameSeparated(QualifiedName) - private var myTargetName: Name | Null = null + private var myTargetName: Name | Uninitialized = initiallyNull private def computeTargetName(targetNameAnnot: Option[Annotation])(using Context): Name = targetNameAnnot match @@ -1704,7 +1704,7 @@ object SymDenotations { private var myTypeParams: List[TypeSymbol] | Null = null private var fullNameCache: SimpleIdentityMap[QualifiedNameKind, Name] = SimpleIdentityMap.empty - private var myMemberCache: EqHashMap[Name, PreDenotation] | Null = null + private var myMemberCache: EqHashMap[Name, PreDenotation] | Uninitialized = initiallyNull private var myMemberCachePeriod: Period = Nowhere /** A cache from types T to baseType(T, C) */ @@ -1755,7 +1755,7 @@ object SymDenotations { invalidateMemberNamesCache() if sym.isWrappedToplevelDef then val outerCache = sym.owner.owner.asClass.classDenot.myMemberCache - if outerCache != null then outerCache.remove(sym.name) + if outerCache != null then outerCache.uncheckedNN.remove(sym.name) override def copyCaches(from: SymDenotation, phase: Phase)(using Context): this.type = { from match { @@ -1838,7 +1838,7 @@ object SymDenotations { // ------ class-specific operations ----------------------------------- - private var myThisType: Type | Null = null + private var myThisType: Type | Uninitialized = initiallyNull /** The this-type depends on the kind of class: * - for a package class `p`: ThisType(TypeRef(Noprefix, p)) @@ -1856,7 +1856,7 @@ object SymDenotations { ThisType.raw(TypeRef(pre, cls)) } - private var myTypeRef: TypeRef | Null = null + private var myTypeRef: TypeRef | Uninitialized = initiallyNull override def typeRef(using Context): TypeRef = { if (myTypeRef == null) myTypeRef = super.typeRef @@ -2628,8 +2628,8 @@ object SymDenotations { def apply(module: TermSymbol, modcls: ClassSymbol): LazyType = this private var myDecls: Scope = EmptyScope - private var mySourceModule: Symbol | Null = null - private var myModuleClass: Symbol | Null = null + private var mySourceModule: Symbol | Uninitialized = initiallyNull + private var myModuleClass: Symbol | Uninitialized = initiallyNull private var mySourceModuleFn: Context ?=> Symbol = LazyType.NoSymbolFn private var myModuleClassFn: Context ?=> Symbol = LazyType.NoSymbolFn diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 7c3f1ae36017..ce1d212f9b8f 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -65,7 +65,7 @@ object Symbols { myCoord = c } - private var myDefTree: Tree | Null = null + private var myDefTree: Tree | Uninitialized = initiallyNull /** The tree defining the symbol at pickler time, EmptyTree if none was retained */ def defTree: Tree = diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index b3aaca843c10..8b15eb522436 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -49,7 +49,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling needsGc = false if Config.checkTypeComparerReset then checkReset() - private var pendingSubTypes: util.MutableSet[(Type, Type)] | Null = null + private var pendingSubTypes: util.MutableSet[(Type, Type)] | Uninitialized = initiallyNull private var recCount = 0 private var monitored = false diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 2cfdd08128ce..6f779e1c30b0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -796,7 +796,7 @@ object TypeOps: // // See tests/patmat/i3938.scala class InferPrefixMap extends TypeMap { - var prefixTVar: Type | Null = null + var prefixTVar: Type | Uninitialized = initiallyNull def apply(tp: Type): Type = tp match { case ThisType(tref: TypeRef) if !tref.symbol.isStaticOwner => if (tref.symbol.is(Module)) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 7d57b4eb2740..41822ca3d9f9 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2073,7 +2073,7 @@ object Types { /** Implementations of this trait cache the results of `narrow`. */ trait NarrowCached extends Type { - private var myNarrow: TermRef | Null = null + private var myNarrow: TermRef | Uninitialized = initiallyNull override def narrow(using Context): TermRef = { if (myNarrow == null) myNarrow = super.narrow myNarrow.nn @@ -2093,7 +2093,7 @@ object Types { assert(prefix.isValueType || (prefix eq NoPrefix), s"invalid prefix $prefix") - private var myName: Name | Null = null + private var myName: Name | Uninitialized = initiallyNull private var lastDenotation: Denotation | Null = null private var lastSymbol: Symbol | Null = null private var checkedPeriod: Period = Nowhere @@ -2881,7 +2881,7 @@ object Types { // `refFn` can be null only if `computed` is true. case class LazyRef(private var refFn: (Context => (Type | Null)) | Null) extends UncachedProxyType with ValueType { - private var myRef: Type | Null = null + private var myRef: Type | Uninitialized = initiallyNull private var computed = false override def tryNormalize(using Context): Type = ref.tryNormalize @@ -3024,7 +3024,7 @@ object Types { val parent: Type = parentExp(this: @unchecked) - private var myRecThis: RecThis | Null = null + private var myRecThis: RecThis | Uninitialized = initiallyNull def recThis: RecThis = { if (myRecThis == null) myRecThis = new RecThisImpl(this) @@ -3441,7 +3441,7 @@ object Types { final def isTypeLambda: Boolean = isInstanceOf[TypeLambda] final def isHigherKinded: Boolean = isInstanceOf[TypeProxy] - private var myParamRefs: List[ParamRefType] | Null = null + private var myParamRefs: List[ParamRefType] | Uninitialized = initiallyNull def paramRefs: List[ParamRefType] = { if myParamRefs == null then @@ -4636,7 +4636,7 @@ object Types { //val id = skid //assert(id != 10) - private var myRepr: Name | Null = null + private var myRepr: Name | Uninitialized = initiallyNull def repr(using Context): Name = { if (myRepr == null) myRepr = SkolemName.fresh() myRepr.nn @@ -4820,7 +4820,7 @@ object Types { def alternatives(using Context): List[Type] = cases.map(caseType) def underlying(using Context): Type = bound - private var myReduced: Type | Null = null + private var myReduced: Type | Uninitialized = initiallyNull private var reductionContext: util.MutableMap[Type, Type] = _ override def tryNormalize(using Context): Type = @@ -4920,8 +4920,8 @@ object Types { decls: Scope, selfInfo: TypeOrSymbol) extends CachedGroundType with TypeType { - private var selfTypeCache: Type | Null = null - private var appliedRefCache: Type | Null = null + private var selfTypeCache: Type | Uninitialized = initiallyNull + private var appliedRefCache: Type | Uninitialized = initiallyNull /** The self type of a class is the conjunction of * - the explicit self type if given (or the info of a given self symbol), and @@ -4948,7 +4948,7 @@ object Types { } // cached because baseType needs parents - private var parentsCache: List[Type] | Null = null + private var parentsCache: List[Type] | Uninitialized = initiallyNull override def parents(using Context): List[Type] = { if (parentsCache == null) diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 0718cc4b8748..420c9b3a5bc6 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -1555,7 +1555,7 @@ object Scanners { /** The enclosing region, which is required to exist */ def enclosing: Region = outer.asInstanceOf[Region] - var knownWidth: IndentWidth | Null = null + var knownWidth: IndentWidth | Uninitialized = initiallyNull /** The indentation width, Zero if not known */ final def indentWidth: IndentWidth = diff --git a/compiler/src/dotty/tools/dotc/reporting/Message.scala b/compiler/src/dotty/tools/dotc/reporting/Message.scala index 0db5d355e963..409ebd6a3bf0 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Message.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Message.scala @@ -69,7 +69,7 @@ abstract class Message(val errorId: ErrorMessageID) { self => */ def canExplain: Boolean = explain.nonEmpty - private var myMsg: String | Null = null + private var myMsg: String | Uninitialized = initiallyNull private var myIsNonSensical: Boolean = false private def dropNonSensical(msg: String): String = diff --git a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala index 32bcc53184b1..23f222944090 100644 --- a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala +++ b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package transform import MegaPhase._ @@ -52,7 +53,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer: Set(refClass(defn.ObjectClass), volatileRefClass(defn.ObjectClass)) } - private var myRefInfo: RefInfo | Null = null + private var myRefInfo: RefInfo | Uninitialized = initiallyNull private def refInfo(using Context): RefInfo = { if (myRefInfo == null) myRefInfo = new RefInfo() myRefInfo.uncheckedNN diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index e72874dfaadd..c0469596003a 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package transform import java.util.IdentityHashMap @@ -44,7 +45,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { val containerFlagsMask: FlagSet = Method | Lazy | Accessor | Module /** A map of lazy values to the fields they should null after initialization. */ - private var lazyValNullables: IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] | Null = _ + private var lazyValNullables: IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] | Uninitialized = _ private def nullableFor(sym: Symbol)(using Context) = { // optimisation: value only used once, we can remove the value from the map val nullables = lazyValNullables.nn.remove(sym) @@ -382,7 +383,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { val thizClass = Literal(Constant(claz.info)) val helperModule = requiredModule("scala.runtime.LazyVals") val getOffset = Select(ref(helperModule), lazyNme.RLazyVals.getOffset) - var offsetSymbol: TermSymbol | Null = null + var offsetSymbol: TermSymbol | Uninitialized = initiallyNull var flag: Tree = EmptyTree var ord = 0 diff --git a/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala b/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala index c1f891d6293a..0a965874ed68 100644 --- a/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala +++ b/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package transform import ast.Trees._, ast.tpd, core._ @@ -35,7 +36,7 @@ class SpecializeFunctions extends MiniPhase { val sym = ddef.symbol val cls = ctx.owner.asClass - var specName: Name | Null = null + var specName: Name | Uninitialized = initiallyNull def isSpecializable = { val paramTypes = ddef.termParamss.head.map(_.symbol.info) diff --git a/compiler/src/dotty/tools/dotc/transform/Splicing.scala b/compiler/src/dotty/tools/dotc/transform/Splicing.scala index fe0c233173b7..44d2fce8f106 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicing.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicing.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package transform import core._ @@ -190,8 +191,8 @@ class Splicing extends MacroTransform: private class SpliceTransformer(spliceOwner: Symbol, isCaptured: Symbol => Boolean) extends Transformer: private var refBindingMap = mutable.Map.empty[Symbol, (Tree, Symbol)] /** Reference to the `Quotes` instance of the current level 1 splice */ - private var quotes: Tree | Null = null // TODO: add to the context - private var healedTypes: PCPCheckAndHeal.QuoteTypeTags | Null = null // TODO: add to the context + private var quotes: Tree | Uninitialized = initiallyNull // TODO: add to the context + private var healedTypes: PCPCheckAndHeal.QuoteTypeTags | Uninitialized = initiallyNull // TODO: add to the context def transformSplice(tree: tpd.Tree, tpe: Type, holeIdx: Int)(using Context): tpd.Tree = assert(level == 0) diff --git a/compiler/src/dotty/tools/dotc/transform/TailRec.scala b/compiler/src/dotty/tools/dotc/transform/TailRec.scala index 71b66c3d0da6..ea7ab557c797 100644 --- a/compiler/src/dotty/tools/dotc/transform/TailRec.scala +++ b/compiler/src/dotty/tools/dotc/transform/TailRec.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package transform import ast.{TreeTypeMap, tpd} @@ -232,7 +233,7 @@ class TailRec extends MiniPhase { var failureReported: Boolean = false /** The `tailLabelN` label symbol, used to encode a `continue` from the infinite `while` loop. */ - private var myContinueLabel: Symbol | Null = _ + private var myContinueLabel: Symbol | Uninitialized = _ def continueLabel(using Context): Symbol = { if (myContinueLabel == null) myContinueLabel = newSymbol(method, TailLabelName.fresh(), Label, defn.UnitType) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 3bd3050ee8f1..7896f0f6999f 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package transform import core.Names.Name @@ -213,7 +214,7 @@ class TreeChecker extends Phase with SymTransformer { } // used to check invariant of lambda encoding - var nestingBlock: untpd.Block | Null = null + var nestingBlock: untpd.Block | Uninitialized = initiallyNull private def withBlock[T](block: untpd.Block)(op: => T): T = { val outerBlock = nestingBlock nestingBlock = block diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index a2c314e12ccf..771cc97135a6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -743,7 +743,7 @@ trait Applications extends Compatibility { type TypedArg = Tree def isVarArg(arg: Trees.Tree[T]): Boolean = untpd.isWildcardStarArg(arg) private var typedArgBuf = new mutable.ListBuffer[Tree] - private var liftedDefs: mutable.ListBuffer[Tree] | Null = null + private var liftedDefs: mutable.ListBuffer[Tree] | Uninitialized = initiallyNull private var myNormalizedFun: Tree = fun init() diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 11f942df31d2..fdd47d537e2e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -100,7 +100,7 @@ object Implicits: */ def companionRefs: TermRefSet = TermRefSet.empty - private var mySingletonClass: ClassSymbol | Null = null + private var mySingletonClass: ClassSymbol | Uninitialized = initiallyNull /** Widen type so that it is neither a singleton type nor a type that inherits from scala.Singleton. */ private def widenSingleton(tp: Type)(using Context): Type = { @@ -842,7 +842,7 @@ trait Implicits: } } - private var synthesizer: Synthesizer | Null = null + private var synthesizer: Synthesizer | Uninitialized = initiallyNull /** Find an implicit argument for parameter `formal`. * Return a failure as a SearchFailureType in the type of the returned tree. diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index b5be2daf873b..735fc2cb9c9d 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -66,7 +66,7 @@ class ImportInfo(symf: Context ?=> Symbol, } mySym.uncheckedNN } - private var mySym: Symbol | Null = _ + private var mySym: Symbol | Uninitialized = _ /** The (TermRef) type of the qualifier of the import clause */ def site(using Context): Type = importSym.info match { @@ -89,9 +89,9 @@ class ImportInfo(symf: Context ?=> Symbol, /** Does the import clause have at least one `given` selector? */ def isGivenImport: Boolean = { ensureInitialized(); myGivenImport } - private var myExcluded: Set[TermName] | Null = null - private var myForwardMapping: SimpleIdentityMap[TermName, TermName] | Null = null - private var myReverseMapping: SimpleIdentityMap[TermName, TermName] | Null = null + private var myExcluded: Set[TermName] | Uninitialized = initiallyNull + private var myForwardMapping: SimpleIdentityMap[TermName, TermName] | Uninitialized = initiallyNull + private var myReverseMapping: SimpleIdentityMap[TermName, TermName] | Uninitialized = initiallyNull private var myWildcardImport: Boolean = false private var myGivenImport: Boolean = false private var myWildcardBound: Type = NoType @@ -180,7 +180,7 @@ class ImportInfo(symf: Context ?=> Symbol, private val isLanguageImport: Boolean = untpd.languageImport(qualifier).isDefined - private var myUnimported: Symbol | Null = _ + private var myUnimported: Symbol | Uninitialized = _ private var featureCache: SimpleIdentityMap[TermName, java.lang.Boolean] = SimpleIdentityMap.empty diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 79e015e0015c..90468d183f3a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -531,7 +531,7 @@ class Namer { typer: Typer => * body and derived clause of the synthetic module class `fromCls`. */ def mergeModuleClass(mdef: Tree, modCls: TypeDef, fromCls: TypeDef): TypeDef = { - var res: TypeDef | Null = null + var res: TypeDef | Uninitialized = initiallyNull val Thicket(trees) = expanded(mdef) val merged = trees.map { tree => if (tree == modCls) { @@ -815,7 +815,7 @@ class Namer { typer: Typer => completer.complete(denot) } - private var completedTypeParamSyms: List[TypeSymbol] | Null = null + private var completedTypeParamSyms: List[TypeSymbol] | Uninitialized = initiallyNull def setCompletedTypeParams(tparams: List[TypeSymbol]) = completedTypeParamSyms = tparams @@ -927,8 +927,8 @@ class Namer { typer: Typer => class TypeDefCompleter(original: TypeDef)(ictx: Context) extends Completer(original)(ictx) with TypeParamsCompleter { - private var myTypeParams: List[TypeSymbol] | Null = null - private var nestedCtx: Context | Null = null + private var myTypeParams: List[TypeSymbol] | Uninitialized = initiallyNull + private var nestedCtx: Context | Uninitialized = initiallyNull assert(!original.isClassDef) /** If completion of the owner of the to be completed symbol has not yet started, diff --git a/compiler/src/dotty/tools/dotc/util/SourceFile.scala b/compiler/src/dotty/tools/dotc/util/SourceFile.scala index b4c65fd64244..cbda9b0697c6 100644 --- a/compiler/src/dotty/tools/dotc/util/SourceFile.scala +++ b/compiler/src/dotty/tools/dotc/util/SourceFile.scala @@ -62,7 +62,7 @@ object ScriptSourceFile { class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends interfaces.SourceFile { import SourceFile._ - private var myContent: Array[Char] | Null = null + private var myContent: Array[Char] | Uninitialized = initiallyNull def content(): Array[Char] = { if (myContent == null) myContent = computeContent diff --git a/compiler/src/dotty/tools/package.scala b/compiler/src/dotty/tools/package.scala index f6bf4314e262..86dd957bb627 100644 --- a/compiler/src/dotty/tools/package.scala +++ b/compiler/src/dotty/tools/package.scala @@ -54,4 +54,16 @@ package object tools { def unreachable(x: Any = "<< this case was declared unreachable >>"): Nothing = throw new MatchError(x) + + /** Marker for `var`s that are initialized to `null`, but cannot be assigned `null` after initialization. + * @example {{{ + * var cache: String | Uninitialized = initiallyNull + * def readCache: String = + * if(cache == null) cache = "hello" + * cache + * }}} + */ + type Uninitialized <: Null + /** Initializer for `var`s of type `Uninitialized` */ + val initiallyNull = null.asInstanceOf[Uninitialized] }