Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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