Skip to content

Commit d8c1ff7

Browse files
committed
Better position and associated file for copied symbols
When a copy of a symbol is created with a new owner, the position and associated file used to be kept as-is, but this can lead to confusing error messages referencing the original definition which might be unrelated to the current error, instead we now copy these fields from the new owner.
1 parent 2a7edab commit d8c1ff7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,19 +797,27 @@ object Symbols {
797797
NoDenotation // force it in order to set `denot` field of NoSymbol
798798

799799
implicit class Copier[N <: Name](sym: Symbol { type ThisName = N })(implicit ctx: Context) {
800-
/** Copy a symbol, overriding selective fields */
800+
/** Copy a symbol, overriding selective fields.
801+
* Note that `coord` and `associatedFile` will be set from the fields in `owner`, not
802+
* the fields in `sym`.
803+
*/
801804
def copy(
802805
owner: Symbol = sym.owner,
803806
name: N = (sym.name: N), // Dotty deviation: type ascription to avoid leaking private sym (only happens in unpickling), won't be needed once #1723 is fixed
804807
flags: FlagSet = sym.flags,
805808
info: Type = sym.info,
806809
privateWithin: Symbol = sym.privateWithin,
807-
coord: Coord = sym.coord,
808-
associatedFile: AbstractFile = sym.associatedFile): Symbol =
810+
coord: Coord = NoCoord, // Can be `= owner.coord` once we boostrap
811+
associatedFile: AbstractFile = null // Can be `= owner.associatedFile` once we boostrap
812+
): Symbol = {
813+
val coord1 = if (coord == NoCoord) owner.coord else coord
814+
val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile
815+
809816
if (sym.isClass)
810-
ctx.newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord, associatedFile)
817+
ctx.newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1)
811818
else
812-
ctx.newSymbol(owner, name, flags, info, privateWithin, coord)
819+
ctx.newSymbol(owner, name, flags, info, privateWithin, coord1)
820+
}
813821
}
814822

815823
/** Makes all denotation operations available on symbols */

0 commit comments

Comments
 (0)