rta: limit the depth of types to avoid infinite loops
[nit.git] / src / rapid_type_analysis.nit
index cec5e78..1d41c34 100644 (file)
@@ -113,6 +113,7 @@ class RapidTypeAnalysis
 
                assert not mtype.need_anchor
                self.live_types.add(mtype)
+               self.check_depth(mtype)
 
                # Collect default attributes
                for cd in mtype.collect_mclassdefs(self.mainmodule)
@@ -185,6 +186,15 @@ class RapidTypeAnalysis
 
                assert not mtype.need_anchor
                self.live_cast_types.add(mtype)
+               self.check_depth(mtype)
+       end
+
+       fun check_depth(mtype: MClassType)
+       do
+               var d = mtype.depth
+               if d > 255 then
+                       self.modelbuilder.toolcontext.fatal_error(null, "Fatal error: limitation in the rapidtype analysis engine: a type depth of {d} is too important, the problematic type is {mtype}.")
+               end
        end
 
        # Run the analysis until all visitable method definitions are visited.