Skip to content

Commit 08b5324

Browse files
committed
Merge pull request #956 from dotty-staging/companion-methods
Remove duplication of companion methods in Scala2Unpickler
2 parents 522c1f2 + a369a81 commit 08b5324

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ object Scala2Unpickler {
119119
val scalacCompanion = denot.classSymbol.scalacLinkedClass
120120

121121
def registerCompanionPair(module: Symbol, claz: Symbol) = {
122-
val companionClassMethod = ctx.synthesizeCompanionMethod(nme.COMPANION_CLASS_METHOD, claz, module)
123-
if (companionClassMethod.exists)
124-
companionClassMethod.entered
122+
def registerCompanionMethod(name: Name, target: Symbol, owner: Symbol) = {
123+
if (!owner.unforcedDecls.lookup(name).exists) {
124+
val companionMethod = ctx.synthesizeCompanionMethod(name, target, owner)
125+
if (companionMethod.exists) {
126+
companionMethod.entered
127+
}
128+
}
129+
}
130+
registerCompanionMethod(nme.COMPANION_CLASS_METHOD, claz, module)
125131
if (claz.isClass) {
126-
val companionModuleMethod = ctx.synthesizeCompanionMethod(nme.COMPANION_MODULE_METHOD, module, claz)
127-
if (companionModuleMethod.exists)
128-
companionModuleMethod.entered
132+
registerCompanionMethod(nme.COMPANION_MODULE_METHOD, module, claz)
129133
}
130134
}
131135

0 commit comments

Comments
 (0)