diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala index d846412185..35bb661377 100644 --- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala +++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala @@ -512,7 +512,15 @@ trait NamesDefaults { self: Analyzer => def companionModuleOf(clazz: Symbol, context: Context) = { var res = clazz.companionModule if (res == NoSymbol) - res = context.lookup(clazz.name.toTermName, clazz.owner) + res = context.lookup(clazz.name.toTermName, clazz.owner).suchThat(sym => + sym.hasFlag(MODULE) && sym.isCoDefinedWith(clazz)) + res + } + + def companionClassOf(module: Symbol, context: Context) = { + var res = module.companionClass + if (res == NoSymbol) + res = context.lookup(module.name.toTypeName, module.owner).suchThat(_.isCoDefinedWith(module)) res } diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 44930ffc81..0da00f5b83 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -290,15 +290,18 @@ trait SyntheticMethods extends ast.TreeDSL { } if (clazz.isModuleClass) { - if (!hasSerializableAnnotation(clazz)) - clazz addAnnotation AnnotationInfo(SerializableAttr.tpe, Nil, Nil) + if (!hasSerializableAnnotation(clazz)) { + val comp = companionClassOf(clazz, context) + if (comp.hasFlag(Flags.CASE) || hasSerializableAnnotation(comp)) + 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)) + if (hasSerializableAnnotation(clazz) && !hasImplementation(nme.readResolve)) ts += readResolveMethod } } catch { |