Skip to content

Commit 7f21e0a

Browse files
authored
Move Symbol copy into Symbol (#16222)
2 parents e7ce165 + 25c3825 commit 7f21e0a

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,27 @@ object Symbols {
348348
def paramVariance(using Context): Variance = denot.variance
349349
def paramRef(using Context): TypeRef = denot.typeRef
350350

351+
/** Copy a symbol, overriding selective fields.
352+
* Note that `coord` and `associatedFile` will be set from the fields in `owner`, not
353+
* the fields in `sym`. */
354+
def copy(using Context)(
355+
owner: Symbol = this.owner,
356+
name: ThisName = name,
357+
flags: FlagSet = this.flags,
358+
info: Type = this.info,
359+
privateWithin: Symbol = this.privateWithin,
360+
coord: Coord = NoCoord, // Can be `= owner.coord` once we bootstrap
361+
associatedFile: AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap
362+
): Symbol = {
363+
val coord1 = if (coord == NoCoord) owner.coord else coord
364+
val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile
365+
366+
if isClass then
367+
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1)
368+
else
369+
newSymbol(owner, name, flags, info, privateWithin, coord1)
370+
}
371+
351372
// -------- Printing --------------------------------------------------------
352373

353374
/** The prefix string to be used when displaying this symbol without denotation */
@@ -469,30 +490,6 @@ object Symbols {
469490

470491
NoDenotation // force it in order to set `denot` field of NoSymbol
471492

472-
extension [N <: Name](sym: Symbol { type ThisName = N })(using Context) {
473-
/** Copy a symbol, overriding selective fields.
474-
* Note that `coord` and `associatedFile` will be set from the fields in `owner`, not
475-
* the fields in `sym`.
476-
*/
477-
def copy(
478-
owner: Symbol = sym.owner,
479-
name: N = sym.name,
480-
flags: FlagSet = sym.flags,
481-
info: Type = sym.info,
482-
privateWithin: Symbol = sym.privateWithin,
483-
coord: Coord = NoCoord, // Can be `= owner.coord` once we bootstrap
484-
associatedFile: AbstractFile | Null = null // Can be `= owner.associatedFile` once we bootstrap
485-
): Symbol = {
486-
val coord1 = if (coord == NoCoord) owner.coord else coord
487-
val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile
488-
489-
if (sym.isClass)
490-
newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1)
491-
else
492-
newSymbol(owner, name, flags, info, privateWithin, coord1)
493-
}
494-
}
495-
496493
/** Makes all denotation operations available on symbols */
497494
implicit def toDenot(sym: Symbol)(using Context): SymDenotation = sym.denot
498495

0 commit comments

Comments
 (0)