Skip to content

Commit

Permalink
Merge: serialization: serialize the Error class and avoid abstract cl…
Browse files Browse the repository at this point in the history
…asses with factories

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>
  • Loading branch information
privat committed Nov 9, 2015
2 parents ea74101 + 7527665 commit 46a54a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/serialization/serialization.nit
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/nitserial.nit
Expand Up @@ -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
Expand Down

0 comments on commit 46a54a9

Please sign in to comment.