modelbuilder: check inheritance loops
authorJean Privat <jean@pryen.org>
Fri, 25 Jan 2013 03:09:12 +0000 (22:09 -0500)
committerJean Privat <jean@pryen.org>
Fri, 25 Jan 2013 03:09:12 +0000 (22:09 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/modelbuilder.nit
tests/sav/error_inh_loop.res [new file with mode: 0644]
tests/sav/fixme/error_inh_loop.res [deleted file]

index 1180ff6..1d866e1 100644 (file)
@@ -567,13 +567,18 @@ class ModelBuilder
        end
 
        # Check the validity of the specialization heirarchy
-       # FIXME Stub implementation
        private fun check_supertypes(nmodule: AModule, nclassdef: AClassdef)
        do
                var mmodule = nmodule.mmodule.as(not null)
                var objectclass = try_get_mclass_by_name(nmodule, mmodule, "Object")
                var mclass = nclassdef.mclass.as(not null)
                var mclassdef = nclassdef.mclassdef.as(not null)
+
+               for s in mclassdef.supertypes do
+                       if s.is_subtype(mmodule, mclassdef.bound_mtype, mclassdef.bound_mtype) then
+                               error(nclassdef, "Error: Inheritance loop for class {mclass} with type {s}")
+                       end
+               end
        end
 
        # Build the classes of the module `nmodule'.
@@ -614,6 +619,11 @@ class ModelBuilder
                        mclassdef.add_in_hierarchy
                end
 
+               # Check inheritance
+               for nclassdef in nmodule.n_classdefs do
+                       self.check_supertypes(nmodule, nclassdef)
+               end
+
                # Check unchecked ntypes
                for nclassdef in nmodule.n_classdefs do
                        if nclassdef isa AStdClassdef then
diff --git a/tests/sav/error_inh_loop.res b/tests/sav/error_inh_loop.res
new file mode 100644 (file)
index 0000000..c204aa0
--- /dev/null
@@ -0,0 +1,3 @@
+error_inh_loop.nit:19,7: Error: Inheritance loop for class A with type B
+error_inh_loop.nit:23,7: Error: Inheritance loop for class B with type C
+error_inh_loop.nit:27,7: Error: Inheritance loop for class C with type A
diff --git a/tests/sav/fixme/error_inh_loop.res b/tests/sav/fixme/error_inh_loop.res
deleted file mode 100644 (file)
index e69de29..0000000