syntax: try to produce an error message for local property conflict
[nit.git] / src / syntax / mmbuilder.nit
index 6acc061..20fb090 100644 (file)
@@ -21,6 +21,23 @@ package mmbuilder
 
 import syntax_base
 
+redef class ToolContext
+       redef fun handle_property_conflict(lc, impls)
+       do
+               var location: nullable Location = null
+               if lc isa MMSrcLocalClass then
+                       var node = lc.node
+                       if node != null then node.location
+               end
+               #if location == null then location = lc.mmmodule.location
+               var clas = new Array[MMLocalClass]
+               for i in impls do
+                       clas.add(i.local_class)
+               end
+               self.fatal_error(location, "Property inheritance conflict in class {lc} for `{impls.first.name}': conflicting properties are defined in {clas.join(", ")}")
+       end
+end
+
 # Class specialization hierarchy sorter
 private class CSHSorter
        super AbstractSorter[MMLocalClass]
@@ -302,7 +319,11 @@ redef class MMImplicitInit
                for a in unassigned_attributes do
                        var sig = a.signature
                        if sig == null then return # Broken attribute definition
-                       params.add( new MMParam( sig.return_type.as(not null), once "recv".to_symbol))
+                       var name = a.name
+                       if name.to_s.first == '_' or name.to_s.first == '@' then
+                               name = a.to_s.substring_from(1).to_symbol
+                       end
+                       params.add(new MMParam(sig.return_type.as(not null), name))
                end
                signature = new MMSignature(params, null, local_class.get_type)
        end
@@ -426,43 +447,38 @@ redef class AModule
        fun import_super_modules(tc: ToolContext, mod: MMSrcModule)
        do
                # Import super-modules
-               var module_names_to_import = new Array[Symbol]
-               var module_visibility = new HashMap[Symbol, Int]
+               var supers = new Array[MMModule]
                var no_import: nullable AImport = null
                for i in n_imports do
                        var n = i.module_name
                        if n != null then
-                               module_names_to_import.add(n)
-                               module_visibility[n] = i.visibility_level
+                               var m = tc.get_module(n, mod)
+                               supers.add(m)
+                               mod.add_super_module(m, i.visibility_level)
                        else
                                no_import = i
                        end
                end
                if no_import != null then
-                       if not module_names_to_import.is_empty then
+                       if not supers.is_empty then
                                tc.error(no_import.location, "Error: Top modules cannot import other modules.")
                        end
-               else if module_names_to_import.is_empty then
+               else if supers.is_empty then
                        var stdname = once "standard".to_symbol
-                       module_names_to_import.add(stdname)
-                       module_visibility[stdname] = 1
+                       var m = tc.get_module(stdname, mod)
+                       supers.add(m)
+                       mod.add_super_module(m, 1)
                end
 
-               mod.import_supers_modules(module_names_to_import)
-
-               for mname in module_names_to_import do
-                       var level = module_visibility[mname]
-                       var m = tc.get_module(mname, mod)
-                       mod.add_super_module(m, level)
-               end
+               tc.add_module(mod, supers)
        end
 end
 
 redef class AModuledecl
        redef fun accept_class_builder(v)
        do
-               if n_id.to_symbol != v.mmmodule.name then
-                       v.error(n_id, "Error: Module name mismatch between {v.mmmodule.name} and {n_id.to_symbol}")
+               if n_name.n_id.to_symbol != v.mmmodule.name then
+                       v.error(n_name.n_id, "Error: Module name mismatch between {v.mmmodule.name} and {n_name.n_id.to_symbol}")
                end
        end
 end
@@ -477,7 +493,7 @@ end
 redef class AStdImport
        redef fun module_name
        do
-               return n_id.to_symbol
+               return n_name.n_id.to_symbol
        end
        redef fun visibility_level
        do