nitc: remove the redundant property `mfree_init`
[nit.git] / src / modelize / modelize_property.nit
index b0c0f60..03d9951 100644 (file)
@@ -153,7 +153,6 @@ redef class ModelBuilder
                        mpropdef.msignature = msignature
                        mpropdef.new_msignature = msignature
                        mprop.is_init = true
-                       nclassdef.mfree_init = mpropdef
                        self.toolcontext.info("{mclassdef} gets a free empty constructor {mpropdef}{msignature}", 3)
                        the_root_init_mmethod = mprop
                        return
@@ -186,11 +185,7 @@ redef class ModelBuilder
                                var sig = mpropdef.msignature
                                if sig == null then continue # Skip broken method
 
-                               for param in sig.mparameters do
-                                       var ret_type = param.mtype
-                                       var mparameter = new MParameter(param.name, ret_type, false)
-                                       mparameters.add(mparameter)
-                               end
+                               mparameters.add_all sig.mparameters
                                initializers.add(mpropdef.mproperty)
                                mpropdef.mproperty.is_autoinit = true
                        end
@@ -360,7 +355,6 @@ redef class ModelBuilder
                var msignature = new MSignature(mparameters, null)
                mpropdef.new_msignature = msignature
                mpropdef.msignature = new MSignature(new Array[MParameter], null) # always an empty real signature
-               nclassdef.mfree_init = mpropdef
                self.toolcontext.info("{mclassdef} gets a free constructor for attributes {mpropdef}{msignature}", 3)
                mclassdef.mclass.root_init = mpropdef
        end
@@ -447,8 +441,7 @@ redef class ModelBuilder
                                var vt = t.mproperty
                                # Because `vt` is possibly unchecked, we have to do the bound-lookup manually
                                var defs = vt.lookup_definitions(mmodule, recv)
-                               # TODO something to manage correctly bound conflicts
-                               assert not defs.is_empty
+                               if defs.is_empty then return false
                                nexts = new Array[MType]
                                for d in defs do
                                        var next = defs.first.bound
@@ -493,9 +486,6 @@ end
 redef class AClassdef
        # Marker used in `ModelBuilder::build_properties`
        private var build_properties_is_done = false
-
-       # The free init (implicitely constructed by the class if required)
-       var mfree_init: nullable MMethodDef = null
 end
 
 redef class MClass
@@ -1065,7 +1055,7 @@ redef class AMethPropdef
                        end
                end
 
-               if mysignature.arity > 0 then
+               if nsig != null then
                        # Check parameters visibility
                        for i in [0..mysignature.arity[ do
                                var nt = nsig.n_params[i].n_type
@@ -1360,6 +1350,8 @@ redef class AAttrPropdef
                        if nexpr != null then
                                if nexpr isa ANewExpr then
                                        mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, nexpr.n_type, true)
+                               else if nexpr isa AAsCastExpr then
+                                       mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, nexpr.n_type, true)
                                else if nexpr isa AIntegerExpr then
                                        var cla: nullable MClass = null
                                        if nexpr.value isa Int then
@@ -1573,31 +1565,32 @@ redef class ATypePropdef
 
        redef fun build_property(modelbuilder, mclassdef)
        do
-               var name = self.n_id.text
-               var mprop = modelbuilder.try_get_mproperty_by_name(self.n_id, mclassdef, name)
+               var name = self.n_qid.n_id.text
+               var mprop = modelbuilder.try_get_mproperty_by_name(self.n_qid, mclassdef, name)
                if mprop == null then
                        var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
                        mprop = new MVirtualTypeProp(mclassdef, name, mvisibility)
                        for c in name.chars do if c >= 'a' and c<= 'z' then
-                               modelbuilder.warning(n_id, "bad-type-name", "Warning: lowercase in the virtual type `{name}`.")
+                               modelbuilder.warning(n_qid, "bad-type-name", "Warning: lowercase in the virtual type `{name}`.")
                                break
                        end
-                       if not self.check_redef_keyword(modelbuilder, mclassdef, self.n_kwredef, false, mprop) then return
                else
-                       if not self.check_redef_keyword(modelbuilder, mclassdef, self.n_kwredef, true, mprop) then return
                        assert mprop isa MVirtualTypeProp
                        check_redef_property_visibility(modelbuilder, self.n_visibility, mprop)
                end
-               mclassdef.mprop2npropdef[mprop] = self
 
                var mpropdef = new MVirtualTypeDef(mclassdef, mprop, self.location)
                self.mpropdef = mpropdef
-               modelbuilder.mpropdef2npropdef[mpropdef] = self
                if mpropdef.is_intro then
                        modelbuilder.toolcontext.info("{mpropdef} introduces new type {mprop.full_name}", 4)
                else
                        modelbuilder.toolcontext.info("{mpropdef} redefines type {mprop.full_name}", 4)
                end
+               if not self.check_redef_keyword(modelbuilder, mclassdef, self.n_kwredef, not mpropdef.is_intro, mprop) then
+                       mpropdef.is_broken =true
+               end
+               mclassdef.mprop2npropdef[mprop] = self
+               modelbuilder.mpropdef2npropdef[mpropdef] = self
                set_doc(mpropdef, modelbuilder)
 
                var atfixed = get_single_annotation("fixed", modelbuilder)