diff options
Diffstat (limited to 'src')
3 files changed, 16 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 756863f8f9..5687917e46 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -360,7 +360,7 @@ trait Namers { self: Analyzer => } exists (_.mods hasFlag DEFAULTPARAM) if (hasDefault) { - val m = ensureCompanionObject(tree, companionModuleDef(tree, List(gen.scalaScalaObjectConstr))) + val m = ensureCompanionObject(tree, companionModuleDef(tree)) classAndNamerOfModule(m) = (tree, null) } case tree @ ModuleDef(mods, name, _) => diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index eedf36c400..44930ffc81 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -289,14 +289,17 @@ trait SyntheticMethods extends ast.TreeDSL { ts += impl() } - if (clazz.isModuleClass && hasSerializableAnnotation(clazz)) { - // If you serialize a singleton and then deserialize it twice, - // you will have two instances of your singleton, unless you implement - // the readResolve() method (see http://www.javaworld.com/javaworld/ - // jw-04-2003/jw-0425-designpatterns_p.html) - // question: should we do this for all serializable singletons, or (as currently done) - // only for those that carry a @serializable annotation? - if (!hasImplementation(nme.readResolve)) ts += readResolveMethod + if (clazz.isModuleClass) { + if (!hasSerializableAnnotation(clazz)) + clazz addAnnotation AnnotationInfo(SerializableAttr.tpe, Nil, Nil) + + /** If you serialize a singleton and then deserialize it twice, + * you will have two instances of your singleton, unless you implement + * the readResolve() method (see http://www.javaworld.com/javaworld/ + * jw-04-2003/jw-0425-designpatterns_p.html) + */ + if (!hasImplementation(nme.readResolve)) + ts += readResolveMethod } } catch { case ex: TypeError => diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala index 735cb4a3c4..57540fffef 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala @@ -147,14 +147,15 @@ trait Unapplies extends ast.TreeDSL TypeTree(), Literal(Constant(cdef.name.decode))) - companionModuleDef(cdef, parents ::: List(gen.scalaScalaObjectConstr), List(toString)) + companionModuleDef(cdef, parents, List(toString)) } - def companionModuleDef(cdef: ClassDef, parents: List[Tree], body: List[Tree] = Nil): ModuleDef = atPos(cdef.pos.focus) { + def companionModuleDef(cdef: ClassDef, parents: List[Tree] = Nil, body: List[Tree] = Nil): ModuleDef = atPos(cdef.pos.focus) { + val allParents = parents ::: List( gen.scalaScalaObjectConstr) ModuleDef( Modifiers(cdef.mods.flags & AccessFlags | SYNTHETIC, cdef.mods.privateWithin), cdef.name.toTermName, - Template(parents, emptyValDef, NoMods, Nil, List(Nil), body, cdef.impl.pos.focus)) + Template(allParents, emptyValDef, NoMods, Nil, List(Nil), body, cdef.impl.pos.focus)) } private val caseMods = Modifiers(SYNTHETIC | CASE) |