Merge: niunit: fix after/before test calls
[nit.git] / src / model / model.nit
index ccb7522..b9d6aa2 100644 (file)
@@ -300,18 +300,15 @@ redef class MModule
                var props = self.model.get_mproperties_by_name(name)
                if props == null then return null
                var res: nullable MMethod = null
+               var recvtype = recv.intro.bound_mtype
                for mprop in props do
                        assert mprop isa MMethod
-                       var intro = mprop.intro_mclassdef
-                       for mclassdef in recv.mclassdefs do
-                               if not self.in_importation.greaters.has(mclassdef.mmodule) then continue
-                               if not mclassdef.in_hierarchy.greaters.has(intro) then continue
-                               if res == null then
-                                       res = mprop
-                               else if res != mprop then
-                                       print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
-                                       abort
-                               end
+                       if not recvtype.has_mproperty(self, mprop) then continue
+                       if res == null then
+                               res = mprop
+                       else if res != mprop then
+                               print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
+                               abort
                        end
                end
                return res
@@ -1818,16 +1815,26 @@ class MSignature
                for i in [0..mparameters.length[ do
                        var parameter = mparameters[i]
                        if parameter.is_vararg then
-                               assert vararg_rank == -1
+                               if vararg_rank >= 0 then
+                                       # If there is more than one vararg,
+                                       # consider that additional arguments cannot be mapped.
+                                       vararg_rank = -1
+                                       break
+                               end
                                vararg_rank = i
                        end
                end
                self.vararg_rank = vararg_rank
        end
 
-       # The rank of the ellipsis (`...`) for vararg (starting from 0).
+       # The rank of the main ellipsis (`...`) for vararg (starting from 0).
        # value is -1 if there is no vararg.
        # Example: for "(a: Int, b: Bool..., c: Char)" #-> vararg_rank=1
+       #
+       # From a model POV, a signature can contain more than one vararg parameter,
+       # the `vararg_rank` just indicates the one that will receive the additional arguments.
+       # However, currently, if there is more that one vararg parameter, no one will be the main one,
+       # and additional arguments will be refused.
        var vararg_rank: Int is noinit
 
        # The number of parameters