Merge branch 'error_req_loop'
authorJean Privat <jean@pryen.org>
Thu, 6 Mar 2014 18:03:45 +0000 (13:03 -0500)
committerJean Privat <jean@pryen.org>
Thu, 6 Mar 2014 18:03:45 +0000 (13:03 -0500)
src/modelbuilder.nit
tests/error_req_loop0.nit [new file with mode: 0644]
tests/sav/error_req_loop0.res [new file with mode: 0644]
tests/sav/error_req_loop1.res
tests/sav/error_req_loop2.res
tests/sav/fixme/error_req_loop1.res [deleted file]
tests/sav/fixme/error_req_loop2.res [deleted file]

index c9e5603..a97535e 100644 (file)
@@ -485,6 +485,9 @@ class ModelBuilder
                # Update the file information
                file.mmodule = mmodule
 
+               # Load imported module
+               build_module_importation(nmodule)
+
                return nmodule
        end
 
@@ -507,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
@@ -527,8 +529,6 @@ class ModelBuilder
                nmodules.add(nmodule)
                self.mmodule2nmodule[mmodule] = nmodule
 
-               build_module_importation(nmodule)
-
                return mmodule
        end
 
@@ -555,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
diff --git a/tests/error_req_loop0.nit b/tests/error_req_loop0.nit
new file mode 100644 (file)
index 0000000..5f5b9e3
--- /dev/null
@@ -0,0 +1,15 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import error_req_loop0
diff --git a/tests/sav/error_req_loop0.res b/tests/sav/error_req_loop0.res
new file mode 100644 (file)
index 0000000..fbbc404
--- /dev/null
@@ -0,0 +1 @@
+error_req_loop0.nit:15,8--22: Error: Dependency loop in module error_req_loop0.
index 4917ee2..7cdaea1 100644 (file)
@@ -1 +1 @@
-Error: Dependency loop for module ./error_req_loop1
+error_req_loop1.nit:17,8--22: Error: Dependency loop between modules error_req_loop1 and error_req_loop2.
index 96b92d0..da37cf7 100644 (file)
@@ -1 +1 @@
-Error: Dependency loop for module ./error_req_loop2
+error_req_loop2.nit:17,8--22: Error: Dependency loop between modules error_req_loop2 and error_req_loop1.
diff --git a/tests/sav/fixme/error_req_loop1.res b/tests/sav/fixme/error_req_loop1.res
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/tests/sav/fixme/error_req_loop2.res b/tests/sav/fixme/error_req_loop2.res
deleted file mode 100644 (file)
index e69de29..0000000