diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-07-31 14:14:01 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-08-02 15:51:30 +0200 |
commit | a354ec2a77f83f57680c576758ddfa9234083b9e (patch) | |
tree | c0090d6f6ab663b8c3845838f3a9e96f25168f29 /test/files/run/exprs_serialize.scala | |
parent | a19f0e83bf18a435bac9c984781f66ac3d94822c (diff) | |
download | scala-a354ec2a77f83f57680c576758ddfa9234083b9e.tar.gz scala-a354ec2a77f83f57680c576758ddfa9234083b9e.tar.bz2 scala-a354ec2a77f83f57680c576758ddfa9234083b9e.zip |
first stab at serialization of exprs and tags
Instead of trying to serialize the entire universe and failing miserably
(which happens now), exprs and type tags will now serialize their creators
and deserialize into scala.reflect.basis.
Since creators produced by reification are not serializable right now,
serialization will crash. That's a small improvement over state of the art
functionality-wise, but it's a step forward robustness-wise.
Next step in this direction is generation of serialization code for creators.
Related issues: SI-5919 and SI-5908. Also see the discussion at scala-internals
http://groups.google.com/group/scala-internals/browse_thread/thread/ef63f8b5bd194c7c
Diffstat (limited to 'test/files/run/exprs_serialize.scala')
-rw-r--r-- | test/files/run/exprs_serialize.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/files/run/exprs_serialize.scala b/test/files/run/exprs_serialize.scala new file mode 100644 index 0000000000..075c902a34 --- /dev/null +++ b/test/files/run/exprs_serialize.scala @@ -0,0 +1,28 @@ +import java.io._ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} + +object Test extends App { + def test(expr: Expr[_]) = + try { + val fout = new ByteArrayOutputStream() + val out = new ObjectOutputStream(fout) + out.writeObject(expr) + out.close() + fout.close() + + val fin = new ByteArrayInputStream(fout.toByteArray) + val in = new ObjectInputStream(fin) + val reexpr = in.readObject().asInstanceOf[scala.reflect.basis.Expr[_]].in(cm) + in.close() + fin.close() + + println(reexpr) + } catch { + case ex: Exception => + println(ex) + } + + test(reify(2)) + test(reify{def foo = "hello"; foo + "world!"}) +}
\ No newline at end of file |