diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-11-10 10:39:40 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-11-10 10:39:40 +0000 |
commit | eea79567f1a02299f714daec11faf008d40648bd (patch) | |
tree | 9e4e3708a0cebd2beb0f8bd0b00af84f7ddc28d9 | |
parent | a0159da70da18f65863947aa4d016ca52fd7bb4f (diff) | |
download | scala-eea79567f1a02299f714daec11faf008d40648bd.tar.gz scala-eea79567f1a02299f714daec11faf008d40648bd.tar.bz2 scala-eea79567f1a02299f714daec11faf008d40648bd.zip |
fixed #2511.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Mixin.scala | 5 | ||||
-rw-r--r-- | test/files/jvm/t2511.check | 1 | ||||
-rw-r--r-- | test/files/jvm/t2511.scala | 30 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 36479586a7..0daad7f2a7 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -278,13 +278,16 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { // member is a value of type unit. No field needed ; case _ => + // atPhase: the private field is moved to the implementation class by erasure, + // so it can no longer be found in the member's owner (the trait) + val accessed = atPhase(currentRun.picklerPhase)(member.accessed) // otherwise mixin a field as well addMember(clazz, clazz.newValue(member.pos, nme.getterToLocal(member.name)) setFlag (LOCAL | PRIVATE | member.getFlag(MUTABLE | LAZY)) setFlag (if (!member.hasFlag(STABLE)) MUTABLE else 0) setInfo member.tpe.resultType - setAnnotations member.annotations) + setAnnotations accessed.annotations) } } } else if (member hasFlag SUPERACCESSOR) { // mixin super accessors diff --git a/test/files/jvm/t2511.check b/test/files/jvm/t2511.check new file mode 100644 index 0000000000..ec747fa47d --- /dev/null +++ b/test/files/jvm/t2511.check @@ -0,0 +1 @@ +null
\ No newline at end of file diff --git a/test/files/jvm/t2511.scala b/test/files/jvm/t2511.scala new file mode 100644 index 0000000000..d4b5e83d0f --- /dev/null +++ b/test/files/jvm/t2511.scala @@ -0,0 +1,30 @@ +object Test { + + import java.io._ + + trait IMyMessage extends Serializable { + @transient var message: String = null + } + + class MyMessage extends IMyMessage + + def serialize = { + val buf = new ByteArrayOutputStream(10000) + val out = new ObjectOutputStream(buf) + val m = new MyMessage + m.message = "foo" + out.writeObject(m) + out.flush + buf.toByteArray + } + + def unserialize(buf:Array[Byte]) = { + val in = new ObjectInputStream(new ByteArrayInputStream(buf)) + in.readObject.asInstanceOf[MyMessage] + } + + def main(args: Array[String]) { + val m = unserialize(serialize) + println(m.message) + } +} |