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

src/loader.nit
src/modelize/modelize_class.nit

index 14ec4fe..6c5bbf6 100644 (file)
@@ -455,6 +455,19 @@ redef class ModelBuilder
                        end
                end
 
+               # Check for conflicting module names in the project
+               if mgroup != null then
+                       var others = model.get_mmodules_by_name(mod_name)
+                       if others != null then for other in others do
+                               if other.mgroup!= null and other.mgroup.mproject == mgroup.mproject then
+                                       var node: ANode
+                                       if decl == null then node = nmodule else node = decl.n_name
+                                       error(node, "Error: A module named `{other.full_name}` already exists at {other.location}")
+                                       break
+                               end
+                       end
+               end
+
                # Create the module
                var mmodule = new MModule(model, mgroup, mod_name, nmodule.location)
                nmodule.mmodule = mmodule
index 5112e25..470afb2 100644 (file)
@@ -97,6 +97,18 @@ redef class ModelBuilder
                                error(nclassdef, "Redef error: No imported class {name} to refine.")
                                return
                        end
+
+                       # Check for conflicting class full-names in the project
+                       if mmodule.mgroup != null and mvisibility >= protected_visibility then
+                               var mclasses = model.get_mclasses_by_name(name)
+                               if mclasses != null then for other in mclasses do
+                                       if other.intro_mmodule.mgroup != null and other.intro_mmodule.mgroup.mproject == mmodule.mgroup.mproject then
+                                               error(nclassdef, "Error: A class named `{other.full_name}` is already defined in module `{other.intro_mmodule}` at {other.intro.location}.")
+                                               break
+                                       end
+                               end
+                       end
+
                        mclass = new MClass(mmodule, name, names, mkind, mvisibility)
                        #print "new class {mclass}"
                else if nclassdef isa AStdClassdef and nmodule.mclass2nclassdef.has_key(mclass) then