modelize: implements services of APropdef as noop (instead of abstract)
[nit.git] / src / modelize / modelize_property.nit
index 01c0166..5d93adf 100644 (file)
@@ -45,11 +45,16 @@ redef class ModelBuilder
        # Retrieve the associated AST node of a mpropertydef.
        # This method is used to associate model entity with syntactic entities.
        #
-       # If the property definition is not associated with a node, returns node.
+       # If the property definition is not associated with a node, returns `null`.
        fun mpropdef2node(mpropdef: MPropDef): nullable ANode
        do
-               var res: nullable ANode = mpropdef2npropdef.get_or_null(mpropdef)
-               if res != null then return res
+               var res
+               res = mpropdef2npropdef.get_or_null(mpropdef)
+               if res != null then
+                       # Run the phases on it
+                       toolcontext.run_phases_on_npropdef(res)
+                       return res
+               end
                if mpropdef isa MMethodDef and mpropdef.mproperty.is_root_init then
                        res = mclassdef2nclassdef.get_or_null(mpropdef.mclassdef)
                        if res != null then return res
@@ -66,6 +71,8 @@ redef class ModelBuilder
                if n == null then return res
                for npropdef in n.n_propdefs do
                        if npropdef isa AAttrPropdef then
+                               # Run the phases on it
+                               toolcontext.run_phases_on_npropdef(npropdef)
                                res.add(npropdef)
                        end
                end
@@ -398,9 +405,9 @@ redef class APropdef
        # The associated propdef once build by a `ModelBuilder`
        var mpropdef: nullable MPROPDEF is writable
 
-       private fun build_property(modelbuilder: ModelBuilder, mclassdef: MClassDef) is abstract
-       private fun build_signature(modelbuilder: ModelBuilder) is abstract
-       private fun check_signature(modelbuilder: ModelBuilder) is abstract
+       private fun build_property(modelbuilder: ModelBuilder, mclassdef: MClassDef) do end
+       private fun build_signature(modelbuilder: ModelBuilder) do end
+       private fun check_signature(modelbuilder: ModelBuilder) do end
        private fun new_property_visibility(modelbuilder: ModelBuilder, mclassdef: MClassDef, nvisibility: nullable AVisibility): MVisibility
        do
                var mvisibility = public_visibility
@@ -822,18 +829,21 @@ redef class AMethPropdef
                                for i in [0..mysignature.arity[ do
                                        var myt = mysignature.mparameters[i].mtype
                                        var prt = msignature.mparameters[i].mtype
-                                       if not myt.is_subtype(mmodule, mclassdef.bound_mtype, prt) or
-                                                       not prt.is_subtype(mmodule, mclassdef.bound_mtype, myt) then
-                                               modelbuilder.error(nsig.n_params[i], "Redef Error: Wrong type for parameter `{mysignature.mparameters[i].name}'. found {myt}, expected {prt} as in {mpropdef.mproperty.intro}.")
+                                       var node = nsig.n_params[i]
+                                       if not modelbuilder.check_sametype(node, mmodule, mclassdef.bound_mtype, myt, prt) then
+                                               modelbuilder.error(node, "Redef Error: Wrong type for parameter `{mysignature.mparameters[i].name}'. found {myt}, expected {prt} as in {mpropdef.mproperty.intro}.")
                                        end
                                end
                        end
                        if precursor_ret_type != null then
+                               var node: nullable ANode = null
+                               if nsig != null then node = nsig.n_type
+                               if node == null then node = self
                                if ret_type == null then
                                        # Inherit the return type
                                        ret_type = precursor_ret_type
-                               else if not ret_type.is_subtype(mmodule, mclassdef.bound_mtype, precursor_ret_type) then
-                                       modelbuilder.error(nsig.n_type.as(not null), "Redef Error: Wrong return type. found {ret_type}, expected {precursor_ret_type} as in {mpropdef.mproperty.intro}.")
+                               else if not modelbuilder.check_subtype(node, mmodule, mclassdef.bound_mtype, ret_type, precursor_ret_type) then
+                                       modelbuilder.error(node, "Redef Error: Wrong return type. found {ret_type}, expected {precursor_ret_type} as in {mpropdef.mproperty.intro}.")
                                end
                        end
                end
@@ -1155,21 +1165,20 @@ redef class AAttrPropdef
                                for i in [0..mysignature.arity[ do
                                        var myt = mysignature.mparameters[i].mtype
                                        var prt = msignature.mparameters[i].mtype
-                                       if not myt.is_subtype(mmodule, mclassdef.bound_mtype, prt) or
-                                                       not prt.is_subtype(mmodule, mclassdef.bound_mtype, myt) then
-                                               var node: ANode
-                                               if nsig != null then node = nsig else node = self
+                                       var node: ANode
+                                       if nsig != null then node = nsig else node = self
+                                       if not modelbuilder.check_sametype(node, mmodule, mclassdef.bound_mtype, myt, prt) then
                                                modelbuilder.error(node, "Redef Error: Wrong type for parameter `{mysignature.mparameters[i].name}'. found {myt}, expected {prt}.")
                                        end
                                end
                        end
                        if precursor_ret_type != null then
+                               var node: ANode
+                               if nsig != null then node = nsig else node = self
                                if ret_type == null then
                                        # Inherit the return type
                                        ret_type = precursor_ret_type
-                               else if not ret_type.is_subtype(mmodule, mclassdef.bound_mtype, precursor_ret_type) then
-                                       var node: ANode
-                                       if nsig != null then node = nsig else node = self
+                               else if not modelbuilder.check_subtype(node, mmodule, mclassdef.bound_mtype, ret_type, precursor_ret_type) then
                                        modelbuilder.error(node, "Redef Error: Wrong return type. found {ret_type}, expected {precursor_ret_type}.")
                                end
                        end
@@ -1276,7 +1285,7 @@ redef class ATypePropdef
                                modelbuilder.warning(n_type, "refine-type", "Redef Error: a virtual type cannot be refined.")
                                break
                        end
-                       if not bound.is_subtype(mmodule, anchor, supbound) then
+                       if not modelbuilder.check_subtype(n_type, mmodule, anchor, bound, supbound) then
                                modelbuilder.error(n_type, "Redef Error: Wrong bound type. Found {bound}, expected a subtype of {supbound}, as in {p}.")
                                break
                        end