Skip to content

Commit d01ecb7

Browse files
committed
Add companion class methods for files read from scala & java
1 parent 13a05d5 commit d01ecb7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/dotty/tools/dotc/core/pickling/ClassfileParser.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,20 @@ class ClassfileParser(
130130
for (i <- 0 until in.nextChar) parseMember(method = true)
131131
classInfo = parseAttributes(classRoot.symbol, classInfo)
132132
if (isAnnotation) addAnnotationConstructor(classInfo)
133+
if (classRoot.exists) syntecizeCompanionMethod(nme.COMPANION_CLASS_METHOD, classRoot, moduleRoot)
134+
133135
setClassInfo(classRoot, classInfo)
134136
setClassInfo(moduleRoot, staticInfo)
135137
}
136138

139+
def syntecizeCompanionMethod(name: TermName, ret: SymDenotation, owner: SymDenotation)(implicit ctx: Context) = {
140+
if(owner.exists) ctx.newSymbol(
141+
owner = owner.symbol,
142+
name = name,
143+
flags = Flags.Synthetic | Flags.Private,
144+
info = ExprType(ret.typeRef)).entered
145+
}
146+
137147
/** Add type parameters of enclosing classes */
138148
def addEnclosingTParams()(implicit ctx: Context): Unit = {
139149
var sym = classRoot.owner

src/dotty/tools/dotc/core/pickling/UnPickler.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ object UnPickler {
118118
denot.owner.thisType select denot.sourceModule
119119
else selfInfo
120120
if (!(denot.flagsUNSAFE is JavaModule)) ensureConstructor(denot.symbol.asClass, decls)
121+
if (denot.flagsUNSAFE is Module) {
122+
val scalacCompanion = denot.classSymbol.scalacLinkedClass
123+
if (scalacCompanion.exists)
124+
ctx.newSymbol(
125+
owner = denot.classSymbol,
126+
name = nme.COMPANION_CLASS_METHOD,
127+
flags = Flags.Synthetic | Flags.Private,
128+
info = ExprType(scalacCompanion.typeRef)).entered
129+
}
130+
121131
denot.info = ClassInfo(denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost)
122132
}
123133
}

0 commit comments

Comments
 (0)