Skip to content

Commit

Permalink
Move Symbol copy into Symbol (#16222)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarter authored Oct 24, 2022
2 parents e7ce165 + 25c3825 commit 7f21e0a
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 7f21e0a

Please sign in to comment.