Skip to content

Duplication of companion methods after using FromTasty fixed #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
14 changes: 10 additions & 4 deletions src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
}

private val symAtAddr = new mutable.HashMap[Addr, Symbol]
private val unpickledSyms = new mutable.HashSet[Symbol]
private val treeAtAddr = new mutable.HashMap[Addr, Tree]
private val typeAtAddr = new mutable.HashMap[Addr, Type] // currently populated only for types that are known to be SHAREd.
private var stubs: Set[Symbol] = Set()

private var roots: Set[SymDenotation] = null

private def registerSym(addr: Addr, sym: Symbol) = {
symAtAddr(addr) = sym
unpickledSyms += sym
}

/** Enter all toplevel classes and objects into their scopes
* @param roots a set of SymDenotations that should be overwritten by unpickling
*/
Expand Down Expand Up @@ -206,7 +212,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
OrType(readType(), readType())
case BIND =>
val sym = ctx.newSymbol(ctx.owner, readName().toTypeName, BindDefinedType, readType())
symAtAddr(start) = sym
registerSym(start, sym)
TypeRef.withFixedSym(NoPrefix, sym.name, sym)
case POLYtype =>
val (names, paramReader) = readNamesSkipParams[TypeName]
Expand Down Expand Up @@ -404,7 +410,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
} // TODO set position
sym.annotations = annots
ctx.enter(sym)
symAtAddr(start) = sym
registerSym(start, sym)
if (isClass) {
sym.completer.withDecls(newScope)
forkAt(templateStart).indexTemplateParams()(localContext(sym))
Expand Down Expand Up @@ -590,7 +596,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
case TYPEDEF | TYPEPARAM =>
if (sym.isClass) {
val companion = sym.scalacLinkedClass
if (companion != NoSymbol) {
if (companion != NoSymbol && unpickledSyms.contains(companion)) {
import transform.SymUtils._
if (sym is Flags.ModuleClass) sym.registerCompanionMethod(nme.COMPANION_CLASS_METHOD, companion)
else sym.registerCompanionMethod(nme.COMPANION_MODULE_METHOD, companion)
Expand Down Expand Up @@ -809,7 +815,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
val name = readName()
val info = readType()
val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, info)
symAtAddr(start) = sym
registerSym(start, sym)
Bind(sym, readTerm())
case ALTERNATIVE =>
Alternative(until(end)(readTerm()))
Expand Down