diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2010-08-17 17:15:08 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2010-08-17 17:15:08 +0000 |
commit | e1232ab57a1f1e669b985debcfd0271768732384 (patch) | |
tree | ea87557f3e86f6c0a8d97ef50b82b3a58d255cf3 /src/compiler | |
parent | 385775c0c565163f2c1a699c33ba19e6dcc4ab12 (diff) | |
download | scala-e1232ab57a1f1e669b985debcfd0271768732384.tar.gz scala-e1232ab57a1f1e669b985debcfd0271768732384.tar.bz2 scala-e1232ab57a1f1e669b985debcfd0271768732384.zip |
better fix for see #3667.
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 { |