From c69e0a9b8262bcf1e97f53d65097fcfa21dba644 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Thu, 24 Jul 2008 09:17:25 +0000 Subject: Fixed #552 and #1116. Reviewed by Iulian. --- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 13 ++-------- .../scala/tools/nsc/transform/CleanUp.scala | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'src') 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) } -- cgit v1.2.3