# Skip if we are not interested
if nat.n_atid.n_id.text != "auto_serializable" then return
if not nclassdef isa AStdClassdef then
- toolcontext.error(nclassdef.location, "Syntax error: only a concrete class can be automatically serialized.")
+ toolcontext.error(nclassdef.location, "Syntax Error: only a concrete class can be automatically serialized.")
return
end
end
# Add a constructor to the automated nclassdef
- fun generate_deserialization_init(nclassdef: AClassdef)
+ fun generate_deserialization_init(nclassdef: AStdClassdef)
do
+ # Do not generate constructors for abstract classes
+ if nclassdef.n_classkind isa AAbstractClasskind then return
+
var npropdefs = nclassdef.n_propdefs
var code = new Array[String]
code.add " redef fun deserialize_class(name)"
code.add " do"
else
- toolcontext.error(deserializer_npropdef.location, "Annotation error: you cannot define Deserializer::deserialize_class in a module where you use \"auto_serializable\".")
+ toolcontext.error(deserializer_npropdef.location, "Error: you cannot define `Deserializer::deserialize_class` in a module where you use `auto_serializable`.")
return
end
for nclassdef in nclassdefs do
var name = nclassdef.n_id.text
- if nclassdef.n_formaldefs.is_empty then
+ if nclassdef.n_formaldefs.is_empty and
+ not nclassdef.n_classkind isa AAbstractClasskind then
+
code.add " if name == \"{name}\" then return new {name}.from_deserializer(self)"
end
end
redef fun process_nmodule(nmodule)
do
for npropdef in nmodule.inits_to_retype do
- var v = new PreciseTypeVisitor(npropdef, npropdef.mpropdef.mclassdef, toolcontext)
+ var mpropdef = npropdef.mpropdef
+ if mpropdef == null then continue # skip error
+ var v = new PreciseTypeVisitor(npropdef, mpropdef.mclassdef, toolcontext)
npropdef.accept_precise_type_visitor v
end
end