File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -333,8 +333,12 @@ object Scopes {
333
333
}
334
334
335
335
/** remove symbol from this scope if it is present */
336
- final def unlink (sym : Symbol )(implicit ctx : Context ): Unit = {
337
- var e = lookupEntry(sym.name)
336
+ final def unlink (sym : Symbol )(implicit ctx : Context ): Unit =
337
+ unlink(sym, sym.name)
338
+
339
+ /** remove symbol from this scope if it is present under the given name */
340
+ final def unlink (sym : Symbol , name : Name )(implicit ctx : Context ): Unit = {
341
+ var e = lookupEntry(name)
338
342
while (e ne null ) {
339
343
if (e.sym == sym) unlink(e)
340
344
e = lookupNextEntry(e)
Original file line number Diff line number Diff line change @@ -1853,6 +1853,17 @@ object SymDenotations {
1853
1853
}
1854
1854
true
1855
1855
}
1856
+
1857
+ /** Unlink all package members defined in `file` in a previous run. */
1858
+ def unlinkFromFile (file : AbstractFile )(implicit ctx : Context ): Unit = {
1859
+ val scope = unforcedDecls.openForMutations
1860
+ for (sym <- scope.toList.iterator) {
1861
+ // We need to be careful to not force the denotation of `sym` here,
1862
+ // otherwise it will be brought forward to the current run.
1863
+ if (sym.defRunId != ctx.runId && sym.isClass && sym.asClass.assocFile == file)
1864
+ scope.unlink(sym, sym.lastKnownDenotation.name)
1865
+ }
1866
+ }
1856
1867
}
1857
1868
1858
1869
@ sharable object NoDenotation
Original file line number Diff line number Diff line change @@ -349,7 +349,16 @@ class Namer { typer: Typer =>
349
349
}
350
350
val existing = pkgOwner.info.decls.lookup(pid.name)
351
351
352
- if ((existing is Package ) && (pkgOwner eq existing.owner)) existing
352
+ if ((existing is Package ) && (pkgOwner eq existing.owner)) {
353
+ existing.moduleClass.denot match {
354
+ case d : PackageClassDenotation =>
355
+ // Remove existing members coming from a previous compilation of this file,
356
+ // they are obsolete.
357
+ d.unlinkFromFile(ctx.source.file)
358
+ case _ =>
359
+ }
360
+ existing
361
+ }
353
362
else {
354
363
/** If there's already an existing type, then the package is a dup of this type */
355
364
val existingType = pkgOwner.info.decls.lookup(pid.name.toTypeName)
You can’t perform that action at this time.
0 commit comments