modelize: check full-name conflicts for properties
authorJean Privat <jean@pryen.org>
Sun, 28 Dec 2014 04:07:02 +0000 (23:07 -0500)
committerprivat <privat@elitebook.pryen.org>
Fri, 9 Jan 2015 22:34:19 +0000 (17:34 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelize/modelize_property.nit

index 11fa271..01c0166 100644 (file)
@@ -478,6 +478,18 @@ redef class APropdef
                                modelbuilder.error(self, "Redef error: {mclassdef.mclass}::{mprop.name} is an inherited property. To redefine it, add the redef keyword.")
                                return false
                        end
+
+                       # Check for full-name conflicts in the project.
+                       # A public property should have a unique qualified name `project::class::prop`.
+                       if mprop.intro_mclassdef.mmodule.mgroup != null and mprop.visibility >= protected_visibility then
+                               var others = modelbuilder.model.get_mproperties_by_name(mprop.name)
+                               if others != null then for other in others do
+                                       if other != mprop and other.intro_mclassdef.mmodule.mgroup != null and other.intro_mclassdef.mmodule.mgroup.mproject == mprop.intro_mclassdef.mmodule.mgroup.mproject and other.intro_mclassdef.mclass.name == mprop.intro_mclassdef.mclass.name and other.visibility >= protected_visibility then
+                                               modelbuilder.advice(self, "full-name-conflict", "Warning: A property named `{other.full_name}` is already defined in module `{other.intro_mclassdef.mmodule}` for the class `{other.intro_mclassdef.mclass.name}`.")
+                                               break
+                                       end
+                               end
+                       end
                else
                        if not need_redef then
                                modelbuilder.error(self, "Error: No property {mclassdef.mclass}::{mprop.name} is inherited. Remove the redef keyword to define a new property.")