src: use `ASuperExpr::mpropdef` instead of asking the frame or visitors
[nit.git] / src / modelbuilder.nit
index 4e1474d..a97535e 100644 (file)
@@ -420,15 +420,9 @@ class ModelBuilder
 
        # Transform relative paths (starting with '../') into absolute paths
        private fun module_absolute_path(path: String): String do
-               if path.has_prefix("..") then
-                       return getcwd.join_path(path).simplify_path
-               end
-               return path
+               return getcwd.join_path(path).simplify_path
        end
 
-       # loaded module by absolute path
-       private var loaded_nmodules = new HashMap[String, AModule]
-
        # Try to load a module AST using a path.
        # Display an error if there is a problem (IO / lexer / parser) and return null
        fun load_module_ast(filename: String): nullable AModule
@@ -442,11 +436,6 @@ class ModelBuilder
                        return null
                end
 
-               var module_path = module_absolute_path(filename)
-               if loaded_nmodules.keys.has(module_path) then
-                       return loaded_nmodules[module_path]
-               end
-
                self.toolcontext.info("load module {filename}", 2)
 
                # Load the file
@@ -466,7 +455,6 @@ class ModelBuilder
                        return null
                end
 
-               loaded_nmodules[module_path] = nmodule
                return nmodule
        end
 
@@ -497,6 +485,9 @@ class ModelBuilder
                # Update the file information
                file.mmodule = mmodule
 
+               # Load imported module
+               build_module_importation(nmodule)
+
                return nmodule
        end
 
@@ -519,7 +510,6 @@ class ModelBuilder
        end
 
        # Visit the AST and create the `MModule` object
-       # Then, recursively load imported modules
        private fun build_a_mmodule(mgroup: nullable MGroup, mod_name: String, nmodule: AModule): nullable MModule
        do
                # Check the module name
@@ -539,8 +529,6 @@ class ModelBuilder
                nmodules.add(nmodule)
                self.mmodule2nmodule[mmodule] = nmodule
 
-               build_module_importation(nmodule)
-
                return mmodule
        end
 
@@ -567,6 +555,13 @@ class ModelBuilder
                                error(aimport.n_visibility, "Error: only properties can be protected.")
                                return
                        end
+                       if sup == mmodule then
+                               error(aimport.n_name, "Error: Dependency loop in module {mmodule}.")
+                       end
+                       if sup.in_importation < mmodule then
+                               error(aimport.n_name, "Error: Dependency loop between modules {mmodule} and {sup}.")
+                               return
+                       end
                        mmodule.set_visibility_for(sup, mvisibility)
                end
                if stdimport then