-
Notifications
You must be signed in to change notification settings - Fork 1.1k
use methods to find companion class #436
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
Changes from all commits
13a05d5
d01ecb7
25af814
7baead9
880a6f5
5e09d2d
f40c498
0a94d6e
7021570
f2221d0
595c3f6
f9910eb
57027f7
b653007
cdbe81e
042c2f0
84602a3
e907c78
fdc92a6
14e0f72
34f1650
c560648
e5618d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,15 @@ trait Symbols { this: Context => | |
owner.thisType, modcls, parents, decls, TermRef.withSymAndName(owner.thisType, module, name)), | ||
privateWithin, coord, assocFile) | ||
|
||
def synthesizeCompanionMethod(name: Name, target: SymDenotation, owner: SymDenotation)(implicit ctx: Context) = | ||
if(owner.exists && target.exists && !owner.isAbsent && !target.isAbsent) { | ||
val existing = owner.unforcedDecls.lookup(name) | ||
|
||
existing.orElse{ | ||
ctx.newSymbol(owner.symbol, name, Flags.Synthetic | Flags.Private, ExprType(target.typeRef)) | ||
} | ||
} else NoSymbol | ||
|
||
/** Create a package symbol with associated package class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd reformulate as follows:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defining method name based on flags doesn't work here: in order to not force type you will need |
||
* from its non-info fields and a lazy type for loading the package's members. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,24 @@ object UnPickler { | |
denot.owner.thisType select denot.sourceModule | ||
else selfInfo | ||
if (!(denot.flagsUNSAFE is JavaModule)) ensureConstructor(denot.symbol.asClass, decls) | ||
|
||
val scalacCompanion = denot.classSymbol.scalacLinkedClass | ||
|
||
def registerCompanionPair(module: Symbol, claz: Symbol) = { | ||
val companionClassMethod = ctx.synthesizeCompanionMethod(nme.COMPANION_CLASS_METHOD, claz, module) | ||
if (companionClassMethod.exists) | ||
companionClassMethod.entered | ||
val companionModuleMethod = ctx.synthesizeCompanionMethod(nme.COMPANION_MODULE_METHOD, module, claz) | ||
if (companionModuleMethod.exists) | ||
companionModuleMethod.entered | ||
} | ||
|
||
if (denot.flagsUNSAFE is Module) { | ||
registerCompanionPair(denot.classSymbol, scalacCompanion) | ||
} else { | ||
registerCompanionPair(scalacCompanion, denot.classSymbol) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a pity that we still need scalacLinkedClass here, because it means we cannot get rid of the associated complexity of isCoDefinedWith. I would much prefer if we got the linked class directly from the unpickling info, instead of looking at |
||
denot.info = ClassInfo(denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost) | ||
} | ||
} | ||
|
@@ -483,7 +501,11 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: | |
if (isModuleRoot) { | ||
moduleRoot setFlag flags | ||
moduleRoot.symbol | ||
} else ctx.newSymbol(owner, name.asTermName, flags, localMemberUnpickler, coord = start) | ||
} else ctx.newSymbol(owner, name.asTermName, flags, | ||
new LocalUnpickler() withModuleClass(implicit ctx => | ||
owner.info.decls.lookup(name.moduleClassName) | ||
.suchThat(_ is Module).symbol) | ||
, coord = start) | ||
case _ => | ||
errorBadSignature("bad symbol tag: " + tag) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to SyntheticAccessor. When you set mods, its not an Or.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not setting them, I'm using this value to mask previous mods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I misread. Consider the comment withdrawn.