diff options
author | Philipp Haller <hallerp@gmail.com> | 2008-07-29 15:18:07 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2008-07-29 15:18:07 +0000 |
commit | 0c33725df730590e399225b0fe25bd2a1f0a35a4 (patch) | |
tree | 8bd0cfaf742d7066f6a075066ccca7cd8fd7ca53 /test/files/jvm/t1143.scala | |
parent | f4efeb88f2b61f1ad6751988d09d288e77e33c17 (diff) | |
download | scala-0c33725df730590e399225b0fe25bd2a1f0a35a4.tar.gz scala-0c33725df730590e399225b0fe25bd2a1f0a35a4.tar.bz2 scala-0c33725df730590e399225b0fe25bd2a1f0a35a4.zip |
Fixed #1143. Added tests for #1143 and #1116.
Diffstat (limited to 'test/files/jvm/t1143.scala')
-rw-r--r-- | test/files/jvm/t1143.scala | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/files/jvm/t1143.scala b/test/files/jvm/t1143.scala new file mode 100644 index 0000000000..4f4557a2d6 --- /dev/null +++ b/test/files/jvm/t1143.scala @@ -0,0 +1,68 @@ +object Serialize { + @throws(classOf[java.io.IOException]) + def write[A](o: A): Array[Byte] = { + val ba = new java.io.ByteArrayOutputStream(512) + val out = new java.io.ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + @throws(classOf[java.io.IOException]) + @throws(classOf[ClassNotFoundException]) + def read[A](buffer: Array[Byte]): A = { + val in = + new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } +} + +@serializable +@SerialVersionUID(1L) +class VarModel[T](getter: => T, setter: T => Unit) { + Serialize.write(getter) + Serialize.write(setter) + + def this(getter: => T) = this(getter, null) + + def getObject: AnyRef = getter.asInstanceOf[AnyRef] + + def setObject(v: AnyRef) = { + if (setter == null) + throw new RuntimeException("Tried to set readonly model!") + setter(v.asInstanceOf[T]) + } + + def detach = () +} + +@serializable +@SerialVersionUID(1L) +class Printer(p: VarModel[String]) { + def print = println(p.getObject) +} + +@serializable +@SerialVersionUID(1L) +class Component { +} + +class Form extends Component { +} + +@serializable +@SerialVersionUID(1L) +class Main { + var pass = "pass" + def main(args: Array[String]) { + val f = new Form { + val p = new Printer(new VarModel(pass, pass=_)) + } + () + } +} + +object Test { + def main(args: Array[String]) { + (new Main).main(Array[String]()) + } +} |