summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2010-08-05 15:43:46 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2010-08-05 15:43:46 +0000
commit0a787b6477311a718cbb6abec15df9dfdc12186e (patch)
tree0c4eb20c15a17312c3d1cce51ea68344287a227a /src
parentc690bf16b9dae7fec67b23b2deb105d7bd27621d (diff)
downloadscala-0a787b6477311a718cbb6abec15df9dfdc12186e.tar.gz
scala-0a787b6477311a718cbb6abec15df9dfdc12186e.tar.bz2
scala-0a787b6477311a718cbb6abec15df9dfdc12186e.zip
close #3667.
scala> def ser(o: AnyRef) = new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream()).writeObject(o) ser: (o: AnyRef)Unit scala> @serializable class Outer { | case class Inner(x: Int) | } defined class Outer scala> val o = new Outer o: Outer = Outer@34469729 scala> ser(new o.Inner(1)) scala> o.Inner // initialize the Inner$module field of o res1: o.Inner.type = Inner scala> ser(new o.Inner(1)) java.io.NotSerializableException: Outer$Inner$ review by extempore.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala19
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala7
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)