src/serialization_phase: generate code to be more tolerant to errors
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 29 Jun 2015 02:09:08 +0000 (22:09 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 29 Jun 2015 02:47:04 +0000 (22:47 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/frontend/serialization_phase.nit

index ccecc98..d8ea1e6 100644 (file)
@@ -213,7 +213,7 @@ do
                        var n_type = attribute.n_type
                        var type_name
                        if n_type == null then
-                               # Use a place holder, we will replace it with the infered type after the model phases
+                               # Use a place holder, we will replace it with the inferred type after the model phases
                                type_name = toolcontext.place_holder_type_name
                        else
                                type_name = n_type.type_name
@@ -222,8 +222,17 @@ do
 
                        code.add """
        var {{{name}}} = v.deserialize_attribute("{{{name}}}")
-       assert {{{name}}} isa {{{type_name}}} else print "Unsupported type for `{class_name}::{{{name}}}`, got '{{{{name}}}.class_name}'; expected {{{type_name}}}"
-       self.{{{name}}} = {{{name}}}"""
+       if not {{{name}}} isa {{{type_name}}} then
+               # Check if it was a subjectent error
+               v.errors.add new AttributeTypeError("TODO remove this arg on c_src regen",
+                       self, "{{{name}}}", {{{name}}}, "{{{type_name}}}")
+
+               # Clear subjacent error
+               if v.keep_going == false then return
+       else
+               self.{{{name}}} = {{{name}}}
+       end
+"""
                end
 
                code.add "end"