diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 90b551850cce..9e4730534bf7 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -506,21 +506,6 @@ object Symbols { def MutableSymbolMap[T](): EqHashMap[Symbol, T] = EqHashMap[Symbol, T]() def MutableSymbolMap[T](initialCapacity: Int): EqHashMap[Symbol, T] = EqHashMap[Symbol, T](initialCapacity) -// ---- Factory methods for symbol creation ---------------------- -// -// All symbol creations should be done via the next two methods. - - /** Create a symbol without a denotation. - * Note this uses a cast instead of a direct type refinement because - * it's debug-friendlier not to create an anonymous class here. - */ - def newNakedSymbol[N <: Name](coord: Coord = NoCoord)(using Context): Symbol { type ThisName = N } = - new Symbol(coord, ctx.base.nextSymId).asInstanceOf[Symbol { type ThisName = N }] - - /** Create a class symbol without a denotation. */ - def newNakedClassSymbol(coord: Coord = NoCoord, assocFile: AbstractFile = null)(using Context): ClassSymbol = - new ClassSymbol(coord, assocFile, ctx.base.nextSymId) - // ---- Symbol creation methods ---------------------------------- /** Create a symbol from its fields (info may be lazy) */ @@ -531,20 +516,12 @@ object Symbols { info: Type, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord)(using Context): Symbol { type ThisName = N } = { - val sym = newNakedSymbol[N](coord) + val sym = new Symbol(coord, ctx.base.nextSymId).asInstanceOf[Symbol { type ThisName = N }] val denot = SymDenotation(sym, owner, name, flags, info, privateWithin) sym.denot = denot sym } - /** Create a class symbol from a function producing its denotation */ - def newClassSymbolDenoting(denotFn: ClassSymbol => SymDenotation, - coord: Coord = NoCoord, assocFile: AbstractFile = null)(using Context): ClassSymbol = { - val cls = newNakedClassSymbol(coord, assocFile) - cls.denot = denotFn(cls) - cls - } - /** Create a class symbol from its non-info fields and a function * producing its info (the produced info may be lazy). */ @@ -557,7 +534,7 @@ object Symbols { coord: Coord = NoCoord, assocFile: AbstractFile = null)(using Context): ClassSymbol = { - val cls = newNakedClassSymbol(coord, assocFile) + val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId) val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin) cls.denot = denot cls @@ -620,19 +597,15 @@ object Symbols { assocFile: AbstractFile = null)(using Context): TermSymbol = { val base = owner.thisType - val module = newNakedSymbol[TermName](coord) - val modcls = newNakedClassSymbol(coord, assocFile) val modclsFlags = clsFlags | ModuleClassCreationFlags val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags) - val cdenot = SymDenotation( - modcls, owner, modclsName, modclsFlags, - infoFn(module, modcls), privateWithin) - val mdenot = SymDenotation( - module, owner, name, modFlags | ModuleValCreationFlags, - if (cdenot.isCompleted) TypeRef(owner.thisType, modcls) - else new ModuleCompleter(modcls)) - module.denot = mdenot - modcls.denot = cdenot + val module = newSymbol( + owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord) + val modcls = newClassSymbol( + owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile) + module.info = + if (modcls.isCompleted) TypeRef(owner.thisType, modcls) + else new ModuleCompleter(modcls) module } @@ -802,12 +775,13 @@ object Symbols { originals else { val copies: List[Symbol] = for (original <- originals) yield - original match { - case original: ClassSymbol => - newNakedClassSymbol(original.coord, original.assocFile) - case _ => - newNakedSymbol[original.ThisName](original.coord) - } + val odenot = original.denot + original.copy( + owner = ttmap.mapOwner(odenot.owner), + flags = odenot.flags &~ Touched, + info = NoCompleter, + privateWithin = ttmap.mapOwner(odenot.privateWithin), + coord = original.coord) val ttmap1 = ttmap.withSubstitution(originals, copies) originals.lazyZip(copies) foreach { (original, copy) => val odenot = original.denot @@ -845,13 +819,7 @@ object Symbols { end completer - copy.denot = odenot.copySymDenotation( - symbol = copy, - owner = ttmap1.mapOwner(odenot.owner), - initFlags = odenot.flags &~ Touched, - info = completer, - privateWithin = ttmap1.mapOwner(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here. - annotations = odenot.annotations) + copy.info = completer copy.denot match case cd: ClassDenotation => cd.registeredCompanion = cd.unforcedRegisteredCompanion.subst(originals, copies)