diff options
author | Philipp Haller <hallerp@gmail.com> | 2008-07-24 09:17:25 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2008-07-24 09:17:25 +0000 |
commit | c69e0a9b8262bcf1e97f53d65097fcfa21dba644 (patch) | |
tree | 7dabbb44c6f9f87c42fb872dd2108dd15b5de2f0 /src/compiler | |
parent | 3f9549bd6f4e2d4e2a67b2ba47d5bbbabe3434ef (diff) | |
download | scala-c69e0a9b8262bcf1e97f53d65097fcfa21dba644.tar.gz scala-c69e0a9b8262bcf1e97f53d65097fcfa21dba644.tar.bz2 scala-c69e0a9b8262bcf1e97f53d65097fcfa21dba644.zip |
Fixed #552 and #1116. Reviewed by Iulian.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 13 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/CleanUp.scala | 28 |
2 files changed, 30 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 93b6342177..c00c190b16 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -160,17 +160,8 @@ trait Symbols { new ModuleClassSymbol(this, pos, name) final def newAnonymousClass(pos: Position) = newClass(pos, nme.ANON_CLASS_NAME.toTypeName) - final def newAnonymousFunctionClass(pos: Position) = { - val anonfun = newClass(pos, nme.ANON_FUN_NAME.toTypeName) - def firstNonSynOwner(chain: List[Symbol]): Symbol = (chain: @unchecked) match { - case o :: os => if (o != this && !(o hasFlag SYNTHETIC) && o.isClass) o else firstNonSynOwner(os) - } - val ownerSerial = firstNonSynOwner(ownerChain) hasAttribute SerializableAttr - if (ownerSerial) - anonfun.attributes = - AnnotationInfo(definitions.SerializableAttr.tpe, List(), List()) :: anonfun.attributes - anonfun - } + final def newAnonymousFunctionClass(pos: Position) = + newClass(pos, nme.ANON_FUN_NAME.toTypeName) final def newRefinementClass(pos: Position) = newClass(pos, nme.REFINE_CLASS_NAME.toTypeName) final def newErrorClass(name: Name) = { diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 5a3ecabbca..a647f8c989 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -561,6 +561,34 @@ abstract class CleanUp extends Transform { val res = Block(List(ValDef(tempVar, EmptyTree), newTry), Ident(tempVar)) localTyper.typed(res) + /* Adds @serializable annotation to anonymous function classes + * which do not have references to classes + * which are not marked @serializable. + */ + case cdef @ ClassDef(mods, name, tparams, impl) => + val sym = cdef.symbol + // is this an anonymous function class? + if (sym.hasFlag(SYNTHETIC) && sym.name.toString.contains("anonfun")) { + // check whether all of its field members are of serializable type + val serializable = + sym.info.members forall { m => + m.isMethod || { + val typeSym = m.info.typeSymbol + // Value types are assumed to be serializable, + // reference types must be marked as such. + isValueType(typeSym) || + typeSym.hasAttribute(SerializableAttr) + } + } + + if (serializable) + sym.attributes = + AnnotationInfo(definitions.SerializableAttr.tpe, List(), List()) :: sym.attributes + + copy.ClassDef(tree, mods, name, transformTypeDefs(tparams), transformTemplate(impl)) + } else + super.transform(tree) + case _ => super.transform(tree) } |