Merge: serialization: serialize the Error class and avoid abstract classes with...
authorJean Privat <jean@pryen.org>
Mon, 9 Nov 2015 15:39:16 +0000 (10:39 -0500)
committerJean Privat <jean@pryen.org>
Mon, 9 Nov 2015 15:39:16 +0000 (10:39 -0500)
This PR implements the serialization of the `Error` class manually, it is declared in `core` above the `serialization` module.

Also updates `nitserial` so that it does not attempt to instantiate abstract classes with factories.

@privat I have doubts about the use of `is_abstract` and `is_class`, is it appropriate?

Pull-Request: #1821
Reviewed-by: Jean Privat <jean@pryen.org>

lib/serialization/serialization.nit
src/nitserial.nit

index 7c689b6..5558d66 100644 (file)
@@ -257,3 +257,25 @@ redef class Ref[E]
                v.serialize_attribute("item", first)
        end
 end
+
+redef class Error
+       super Serializable
+
+       redef init from_deserializer(v)
+       do
+               v.notify_of_creation self
+
+               var message = v.deserialize_attribute("message")
+               if not message isa String then message = ""
+               init message
+
+               var cause = v.deserialize_attribute("cause")
+               if cause isa nullable Error then self.cause = cause
+       end
+
+       redef fun core_serialize_to(v)
+       do
+               v.serialize_attribute("message", message)
+               v.serialize_attribute("cause", cause)
+       end
+end
index 83b697e..1c24d69 100644 (file)
@@ -218,6 +218,7 @@ redef class Deserializer
                        if mtype isa MGenericType and
                           mtype.is_subtype(m, null, serializable_type) and
                           mtype.is_visible_from(mmodule) and
+                          mtype.mclass.kind == concrete_kind and
                           not compiled_types.has(mtype) then
 
                                compiled_types.add mtype