From 25c382502a35cc10867ff6cd9dd20b2754af65db Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 20 Oct 2022 14:46:35 +0200 Subject: [PATCH] Move Symbol copy into Symbol --- .../src/dotty/tools/dotc/core/Symbols.scala | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 73fbcca6f6ed..775062c26b0c 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -348,6 +348,27 @@ object Symbols { def paramVariance(using Context): Variance = denot.variance def paramRef(using Context): TypeRef = denot.typeRef + /** Copy a symbol, overriding selective fields. + * Note that `coord` and `associatedFile` will be set from the fields in `owner`, not + * the fields in `sym`. */ + def copy(using Context)( + owner: Symbol = this.owner, + name: ThisName = name, + flags: FlagSet = this.flags, + info: Type = this.info, + privateWithin: Symbol = this.privateWithin, + coord: Coord = NoCoord, // Can be `= owner.coord` once we bootstrap + associatedFile: AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap + ): Symbol = { + val coord1 = if (coord == NoCoord) owner.coord else coord + val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile + + if isClass then + newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1) + else + newSymbol(owner, name, flags, info, privateWithin, coord1) + } + // -------- Printing -------------------------------------------------------- /** The prefix string to be used when displaying this symbol without denotation */ @@ -469,30 +490,6 @@ object Symbols { NoDenotation // force it in order to set `denot` field of NoSymbol - extension [N <: Name](sym: Symbol { type ThisName = N })(using Context) { - /** Copy a symbol, overriding selective fields. - * Note that `coord` and `associatedFile` will be set from the fields in `owner`, not - * the fields in `sym`. - */ - def copy( - owner: Symbol = sym.owner, - name: N = sym.name, - flags: FlagSet = sym.flags, - info: Type = sym.info, - privateWithin: Symbol = sym.privateWithin, - coord: Coord = NoCoord, // Can be `= owner.coord` once we bootstrap - associatedFile: AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap - ): Symbol = { - val coord1 = if (coord == NoCoord) owner.coord else coord - val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile - - if (sym.isClass) - newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1) - else - newSymbol(owner, name, flags, info, privateWithin, coord1) - } - } - /** Makes all denotation operations available on symbols */ implicit def toDenot(sym: Symbol)(using Context): SymDenotation = sym.denot