rename 'package' to 'module'
[nit.git] / src / metamodel / inheritance.nit
index 4d4ece8..ed5518f 100644 (file)
 # limitations under the License.
 
 # Compute importation of classes and inheritance of properties
-package inheritance
+module inheritance
 
 intrude import static_type
 
+redef class MMContext
+       # Method to redefine to handle the property conflicts
+       # FIXME: This is just a bad workaround because of a bad design
+       fun handle_property_conflict(lc: MMLocalClass, impls2: Array[MMLocalProperty])
+       do
+               var glob = impls2.first.global
+               stderr.write("Fatal error: inherit_local_property error\n")
+               print("------- {lc.mmmodule}::{lc} {glob.intro.full_name}")
+               for i in impls2 do
+                       print("   {i.full_name}")
+               end
+               print("------- {glob.property_hierarchy.first}")
+               print("------- {glob.property_hierarchy.to_dot}")
+               exit(1)
+       end
+end
+
 redef class MMModule
        # The root of the class hierarchy
        fun type_any: MMType
@@ -103,7 +120,7 @@ redef class MMLocalClass
                var ancestors = group_ancestors(build_ancestors)
                _ancestors = new HashMap[MMLocalClass, MMAncestor]
 
-               for set in ancestors do
+               for set in ancestors.values do
                        if set.length == 1 then
                                add_ancestor(set.first)
                        else
@@ -264,6 +281,12 @@ redef class MMLocalClass
                        return _local_property_by_global[glob]
                else if has_global_property(glob) then
                        return inherit_local_property(glob)
+               else if not computed_super_classes then
+                       compute_super_classes
+                       computed_ancestors
+                       inherit_global_properties
+                       assert has_global_property(glob)
+                       return inherit_local_property(glob)
                else
                        abort
                end
@@ -430,14 +453,7 @@ redef class MMLocalClass
                        var impls2 = ghier.select_smallests(impls)
                        # Conflict case (FIXME)
                        if impls2.length != 1 then
-                               stderr.write("Fatal error: inherit_local_property error\n")
-                               print("------- {mmmodule}::{self} {glob.intro.full_name}")
-                               for i in impls2 do
-                                       print("   {i.full_name}")
-                               end
-                               print("------- {glob.property_hierarchy.first}")
-                               print("------- {glob.property_hierarchy.to_dot}")
-                               exit(1)
+                               self.mmmodule.context.handle_property_conflict(self, impls2)
                        end
                        impl = impls2.first
                end
@@ -475,7 +491,7 @@ redef class MMAncestor
        do
                tab.add(self)
                stype.local_class.compute_ancestors
-               for anc in stype.local_class.ancestors.as(not null) do
+               for anc in stype.local_class.ancestors.values do
                        var aaa = anc.stype.for_module(stype.mmmodule)
                        var a = aaa.adapt_to(stype).for_module(inheriter.mmmodule)
                        if a.local_class != inheriter.local_class then