X-Git-Url: http://nitlanguage.org diff --git a/src/modelize/modelize_property.nit b/src/modelize/modelize_property.nit index bb4d2cd..0d2e3a6 100644 --- a/src/modelize/modelize_property.nit +++ b/src/modelize/modelize_property.nit @@ -312,28 +312,6 @@ redef class MClassDef var mprop2npropdef: Map[MProperty, APropdef] = new HashMap[MProperty, APropdef] end -redef class Prod - # Join the text of all tokens - # Used to get the 'real name' of method definitions. - fun collect_text: String - do - var v = new TextCollectorVisitor - v.enter_visit(self) - assert v.text != "" - return v.text - end -end - -private class TextCollectorVisitor - super Visitor - var text: String = "" - redef fun visit(n) - do - if n isa Token then text += n.text - n.visit_all(self) - end -end - redef class APropdef # The associated main model entity type MPROPDEF: MPropDef @@ -551,7 +529,7 @@ redef class AMethPropdef name = "init" name_node = n_kwinit else if n_kwnew != null then - name = "init" + name = "new" name_node = n_kwnew else abort @@ -653,7 +631,7 @@ redef class AMethPropdef modelbuilder.error(node, "Redef error: {mpropdef} redefines {mpropdef.mproperty.intro} with {param_names.length} parameter(s), {msignature.arity} expected. Signature is {mpropdef}{msignature}") return end - else if mpropdef.mproperty.is_init then + else if mpropdef.mproperty.is_init and not mpropdef.mproperty.is_new then # FIXME UGLY: inherit signature from a super-constructor for msupertype in mclassdef.supertypes do msupertype = msupertype.anchor_to(mmodule, mclassdef.bound_mtype) @@ -693,6 +671,9 @@ redef class AMethPropdef mparameters.add(mparameter) end + # In `new`-factories, the return type is by default the classtype. + if ret_type == null and mpropdef.mproperty.is_new then ret_type = mclassdef.mclass.mclass_type + msignature = new MSignature(mparameters, ret_type) mpropdef.msignature = msignature mpropdef.is_abstract = self.get_single_annotation("abstract", modelbuilder) != null