Skip to content

Commit 333941a

Browse files
committed
Links between companions after unpickling are added
1 parent 6b061b5 commit 333941a

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,15 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
588588
sym.info = readType()
589589
ValDef(sym.asTerm, readRhs(localCtx))
590590
case TYPEDEF | TYPEPARAM =>
591-
if (sym.isClass)
591+
if (sym.isClass) {
592+
val companion = sym.scalacLinkedClass
593+
if (companion != NoSymbol) {
594+
import transform.SymUtils._
595+
if (sym is Flags.ModuleClass) sym.registerCompanionMethod(nme.COMPANION_CLASS_METHOD, companion)
596+
else sym.registerCompanionMethod(nme.COMPANION_MODULE_METHOD, companion)
597+
}
592598
ta.assignType(untpd.TypeDef(sym.name.asTypeName, readTemplate(localCtx)), sym)
593-
else {
599+
} else {
594600
sym.info = readType()
595601
TypeDef(sym.asType)
596602
}

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

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

121121
def registerCompanionPair(module: Symbol, claz: Symbol) = {
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)
122+
import transform.SymUtils._
123+
module.registerCompanionMethod(nme.COMPANION_CLASS_METHOD, claz)
131124
if (claz.isClass) {
132-
registerCompanionMethod(nme.COMPANION_MODULE_METHOD, module, claz)
125+
claz.registerCompanionMethod(nme.COMPANION_MODULE_METHOD, module)
133126
}
134127
}
135128

src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,13 @@ class SymUtils(val self: Symbol) extends AnyVal {
9999
self.addAnnotations(from.annotationsCarrying(meta))
100100
self
101101
}
102+
103+
def registerCompanionMethod(name: Name, target: Symbol)(implicit ctx: Context) = {
104+
if (!self.unforcedDecls.lookup(name).exists) {
105+
val companionMethod = ctx.synthesizeCompanionMethod(name, target, self)
106+
if (companionMethod.exists) {
107+
companionMethod.entered
108+
}
109+
}
110+
}
102111
}

tests/pos/i0881/A_1.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class A
2+
object A {
3+
implicit val theA: A = new A
4+
}

tests/pos/i0881/B_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class B {
2+
def getA(implicit a: A): A = a
3+
def test = {
4+
getA
5+
}
6+
}

0 commit comments

Comments
 (0)