Merge: Stricter default arguments
authorJean Privat <jean@pryen.org>
Mon, 10 Aug 2015 16:12:51 +0000 (12:12 -0400)
committerJean Privat <jean@pryen.org>
Mon, 10 Aug 2015 16:12:51 +0000 (12:12 -0400)
This change the way that default arguments are handled.

Now, defaults arguments can only follow the used one.
This improve the readability of calls and the association between calls and declarations thus solve a lot of issues of users.

~~~
fun foo(a: nullable Int, b: Int, c: nullable Int) do ...
foo(null,2,null) # OK
foo(null,2) # equivalent
foo(2) # now refused! but previously accepted as equivalent.
~~~

Only exception: the last parameter of an assignment method is always the last argument

~~~
fun foo=(a: nullable Int, b: Int, c: nullable Int, d: nullable Int) do ...
foo(null,2,null) = 0 # OK
foo(null,2) = 0 # equivalent
foo(2) = 0 # now refused! but previously accepted as equivalent
~~~

No specific black magic is added to automatic constructor.
Therefore an optional constructor parameter in a class can becore mandatory in a subclass if a new mandatory attribute is introduced.

~~~
class A
   var a: nullable Int
end
class B
  super A
  var b: Int
end
var a1 = new A(null) # OK
var a2 = new A # equivalent
var b1 = new B(null, 2) # OK
var b2 = new B(2) # now refused! but previously accepted as equivalent
~~~

This issue only required some small adaptation in existing piece of code: nitdoc, sexp, serialization and dom. The latter is PRized independently in #1616 but included here for jenkins.
Most of these changes (first commits) are in fact bugfixes or make the code cleaner so this is an argument in favor of this new stricter specification.

This PR has also the advantage of simplifying the model as the whole policy of the default argument is moved to the typing analysis: it is now just a pure calling convention.

Close #1453

Pull-Request: #1618
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

24 files changed:
lib/serialization/serialization.nit
lib/sexp.nit
src/doc/doc_phases/doc_readme.nit
src/doc/doc_phases/doc_structure.nit
src/model/model.nit
src/modelize/modelize_property.nit
src/neo.nit
src/semantize/typing.nit
tests/base_arg_default.nit
tests/base_arg_default_autoinit.nit
tests/base_arg_named.nit
tests/base_arg_named_inherit.nit
tests/base_arg_order.nit
tests/sav/base_arg_default.res
tests/sav/base_arg_default_alt1.res
tests/sav/base_arg_default_autoinit.res
tests/sav/base_arg_default_autoinit_alt1.res
tests/sav/base_arg_named.res
tests/sav/base_arg_named_alt1.res
tests/sav/base_arg_named_inherit.res
tests/sav/base_arg_named_inherit_alt1.res
tests/sav/base_arg_named_inherit_alt2.res
tests/sav/base_arg_named_inherit_alt3.res [new file with mode: 0644]
tests/sav/base_arg_order.res

index 1fec7e9..e3ca6b3 100644 (file)
@@ -131,7 +131,7 @@ abstract class Deserializer
        # When at `true`, this may cause the accumulation of a lot of entries in `errors`.
        #
        # Default at `true`.
-       var keep_going: nullable Bool is writable
+       var keep_going: nullable Bool = null is writable
 
        # Errors encountered in the last call to `deserialize`
        var errors = new Array[Error]
index 491abdc..fa7c513 100644 (file)
@@ -99,9 +99,8 @@ class SExpProcessor
                var srclen = src.length
                var delims = once ['(', ')', '"']
                ignore_whitespaces
-               if pos >= srclen then return new SExpError("Empty S-Expression", location = new Location(line, line_offset))
+               if pos >= srclen then return new SExpError(new Location(line, line_offset), "Empty S-Expression")
                var c = src[pos]
-               if pos >= srclen then return new SExpError("Empty S-Expression")
                if c == '(' then
                        var cnt = new SExp
                        var loc = new Location(line, line_offset)
@@ -116,30 +115,32 @@ class SExpProcessor
                                pos += 1
                                return cnt
                        else
-                               return new SExpError("Incomplete S-Expression", location = loc)
+                               return new SExpError(loc, "Incomplete S-Expression")
                        end
                else if c == '"' then
                        var stdq = pos
+                       var loc = new Location(line, line_offset)
                        pos += 1
                        ignore_until("\"")
                        pos += 1
                        var endq = pos
-                       return new SExpDQString(src.substring(stdq, endq - stdq))
+                       return new SExpDQString(loc, src.substring(stdq, endq - stdq))
                else
                        var stid = pos
+                       var loc = new Location(line, line_offset)
                        while pos < srclen and not c.is_whitespace and not delims.has(c) do
                                c = src[pos]
                                pos += 1
                        end
                        if delims.has(c) or c.is_whitespace then pos -= 1
-                       if pos >= srclen then return new SExpError("Invalid S-Expression")
+                       if pos >= srclen then return new SExpError(loc, "Invalid S-Expression")
                        var endid = pos
                        var cntstr = src.substring(stid, endid - stid)
                        var cnt: SExpEntity
                        if cntstr.is_numeric then
-                               cnt = new SExpFloat(cntstr.to_f)
+                               cnt = new SExpFloat(loc, cntstr.to_f)
                        else
-                               cnt = new SExpId(cntstr)
+                               cnt = new SExpId(loc, cntstr)
                        end
                        return cnt
                end
index 0a43edb..4e5e2dc 100644 (file)
@@ -256,12 +256,12 @@ redef class ListCommand
                end
                var mentity = res.first
                if mentity isa MModule then
-                       v.add_article new MEntitiesListArticle("Classes", mentity.mclassdefs)
+                       v.add_article new MEntitiesListArticle("Classes", null, mentity.mclassdefs)
                else if mentity isa MClass then
                        var mprops = mentity.collect_intro_mproperties(public_visibility)
-                       v.add_article new MEntitiesListArticle("Methods", mprops.to_a)
+                       v.add_article new MEntitiesListArticle("Methods", null, mprops.to_a)
                else if mentity isa MClassDef then
-                       v.add_article new MEntitiesListArticle("Methods", mentity.mpropdefs)
+                       v.add_article new MEntitiesListArticle("Methods", null, mentity.mpropdefs)
                end
        end
 end
index 96bc219..aaf137f 100644 (file)
@@ -55,7 +55,7 @@ redef class OverviewPage
                sorter.sort mprojects
                var section = new DocSection("projects.section", "Projects")
                for mproject in mprojects do
-                       section.add_child new DefinitionArticle("{mproject.nitdoc_id}.definition", mproject)
+                       section.add_child new DefinitionArticle("{mproject.nitdoc_id}.definition", null, mproject)
                end
                article.add_child section
        end
@@ -69,18 +69,18 @@ redef class SearchPage
                v.name_sorter.sort(mclasses)
                var mprops = doc.mproperties.to_a
                v.name_sorter.sort(mprops)
-               root.add_child new IndexArticle("index.article", mmodules, mclasses, mprops)
+               root.add_child new IndexArticle("index.article", null, mmodules, mclasses, mprops)
        end
 end
 
 redef class MGroupPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", null, mentity)
                root.add_child section
                if mentity.is_root then
-                       section.add_child new IntroArticle("{mentity.mproject.nitdoc_id}.intro", mentity.mproject)
+                       section.add_child new IntroArticle("{mentity.mproject.nitdoc_id}.intro", null, mentity.mproject)
                else
-                       section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
+                       section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", null, mentity)
                end
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
@@ -90,11 +90,11 @@ redef class MGroupPage
                concerns.sort_with(v.concerns_sorter)
                mentity.mproject.booster_rank = 0
                mentity.booster_rank = 0
-               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", null, mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", null, mentity)
                        if mentity isa MModule then
-                               ssection.add_child new DefinitionArticle("{mentity.nitdoc_id}.definition", mentity)
+                               ssection.add_child new DefinitionArticle("{mentity.nitdoc_id}.definition", null, mentity)
                        end
                        section.add_child ssection
                end
@@ -103,9 +103,9 @@ end
 
 redef class MModulePage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", null, mentity)
                root.add_child section
-               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
+               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", null, mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME avoid diff
@@ -116,25 +116,25 @@ redef class MModulePage
                mentity.mgroup.mproject.booster_rank = 0
                mentity.mgroup.booster_rank = 0
                mentity.booster_rank = 0
-               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", null, mentity, concerns)
                # reference list
                for mentity in concerns do
-                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", null, mentity)
                        if mentity isa MModule then
                                var mclasses = mclasses_for_mmodule(mentity).to_a
                                v.name_sorter.sort(mclasses)
                                for mclass in mclasses do
                                        var article = new DefinitionListArticle(
-                                               "{mclass.intro.nitdoc_id}.definition-list", mclass)
+                                               "{mclass.intro.nitdoc_id}.definition-list", null, mclass)
                                        var mclassdefs = mclassdefs_for(mclass).to_a
                                        if not mclassdefs.has(mclass.intro) then
                                                article.add_child(new DefinitionArticle(
-                                                       "{mclass.intro.nitdoc_id}.definition", mclass.intro))
+                                                       "{mclass.intro.nitdoc_id}.definition", null, mclass.intro))
                                        end
                                        doc.mainmodule.linearize_mclassdefs(mclassdefs)
                                        for mclassdef in mclassdefs do
                                                article.add_child(new DefinitionArticle(
-                                                       "{mclassdef.nitdoc_id}.definition", mclassdef))
+                                                       "{mclassdef.nitdoc_id}.definition", null, mclassdef))
                                        end
                                        ssection.add_child article
                                end
@@ -168,9 +168,9 @@ end
 
 redef class MClassPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", null, mentity)
                root.add_child section
-               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
+               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", null, mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -184,12 +184,12 @@ redef class MClassPage
                var constructors = new DocSection("{mentity.nitdoc_id}.constructors", "Constructors")
                var minit = mentity.root_init
                if minit != null then
-                       constructors.add_child new DefinitionArticle("{minit.nitdoc_id}.definition", minit)
+                       constructors.add_child new DefinitionArticle("{minit.nitdoc_id}.definition", null, minit)
                end
                section.add_child constructors
-               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", null, mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", null, mentity)
                        if mentity isa MModule then
                                var mprops = mproperties_for(mentity)
                                var by_kind = new PropertiesByKind.with_elements(mprops)
@@ -200,10 +200,10 @@ redef class MClassPage
                                                        if mpropdef isa MMethodDef and mpropdef.mproperty.is_init then
                                                                if mpropdef == minit then continue
                                                                constructors.add_child new DefinitionArticle(
-                                                                       "{mpropdef.nitdoc_id}.definition", mpropdef)
+                                                                       "{mpropdef.nitdoc_id}.definition", null, mpropdef)
                                                        else
                                                                ssection.add_child new DefinitionArticle(
-                                                                       "{mpropdef.nitdoc_id}.definition", mpropdef)
+                                                                       "{mpropdef.nitdoc_id}.definition", null, mpropdef)
                                                        end
                                                end
                                        end
@@ -243,9 +243,9 @@ end
 
 redef class MPropertyPage
        redef fun apply_structure(v, doc) do
-               var section = new MEntitySection("{mentity.nitdoc_name}.section", mentity)
+               var section = new MEntitySection("{mentity.nitdoc_name}.section", null, mentity)
                root.add_child section
-               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", mentity)
+               section.add_child new IntroArticle("{mentity.nitdoc_id}.intro", null, mentity)
                var concerns = self.concerns
                if concerns == null or concerns.is_empty then return
                # FIXME diff hack
@@ -256,16 +256,16 @@ redef class MPropertyPage
                mentity.intro.mclassdef.mmodule.mgroup.mproject.booster_rank = 0
                mentity.intro.mclassdef.mmodule.mgroup.booster_rank = 0
                mentity.intro.mclassdef.mmodule.booster_rank = 0
-               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", mentity, concerns)
+               section.add_child new ConcernsArticle("{mentity.nitdoc_id}.concerns", null, mentity, concerns)
                for mentity in concerns do
-                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", mentity)
+                       var ssection = new ConcernSection("{mentity.nitdoc_id}.concern", null, mentity)
                        if mentity isa MModule then
                                # Add mproperties
                                var mpropdefs = mpropdefs_for(mentity).to_a
                                v.name_sorter.sort(mpropdefs)
                                for mpropdef in mpropdefs do
                                        ssection.add_child new DefinitionArticle(
-                                               "{mpropdef.nitdoc_id}.definition", mpropdef)
+                                               "{mpropdef.nitdoc_id}.definition", null, mpropdef)
                                end
                        end
                        section.add_child ssection
index f0bfe8b..70c635e 100644 (file)
@@ -1813,22 +1813,6 @@ class MSignature
        # The number of parameters
        fun arity: Int do return mparameters.length
 
-       # The number of non-default parameters
-       #
-       # The number of default parameters is then `arity-min_arity`.
-       #
-       # Note that there cannot be both varargs and default prameters, thus
-       # if `vararg_rank != -1` then `min_arity` == `arity`
-       fun min_arity: Int
-       do
-               if vararg_rank != -1 then return arity
-               var res = 0
-               for p in mparameters do
-                       if not p.is_default then res += 1
-               end
-               return res
-       end
-
        redef fun to_s
        do
                var b = new FlatBuffer
@@ -1882,9 +1866,6 @@ class MParameter
        # Is the parameter a vararg?
        var is_vararg: Bool
 
-       # Is the parameter a default one?
-       var is_default: Bool
-
        redef fun to_s
        do
                if is_vararg then
@@ -1900,7 +1881,7 @@ class MParameter
        do
                if not self.mtype.need_anchor then return self
                var newtype = self.mtype.resolve_for(mtype, anchor, mmodule, cleanup_virtual)
-               var res = new MParameter(self.name, newtype, self.is_vararg, self.is_default)
+               var res = new MParameter(self.name, newtype, self.is_vararg)
                return res
        end
 
index 824ac8c..af3ae39 100644 (file)
@@ -186,7 +186,7 @@ redef class ModelBuilder
 
                                for param in sig.mparameters do
                                        var ret_type = param.mtype
-                                       var mparameter = new MParameter(param.name, ret_type, false, ret_type isa MNullableType)
+                                       var mparameter = new MParameter(param.name, ret_type, false)
                                        mparameters.add(mparameter)
                                end
                                initializers.add(npropdef.mpropdef.mproperty)
@@ -208,7 +208,7 @@ redef class ModelBuilder
                                var paramname = mreadpropdef.mproperty.name
                                var ret_type = mreadpropdef.msignature.return_mtype
                                if ret_type == null then return
-                               var mparameter = new MParameter(paramname, ret_type, false, ret_type isa MNullableType)
+                               var mparameter = new MParameter(paramname, ret_type, false)
                                mparameters.add(mparameter)
                                var msetter = npropdef.mwritepropdef
                                if msetter == null then
@@ -277,13 +277,7 @@ redef class ModelBuilder
                                if pd isa MMethodDef then
                                        # Get the signature resolved for the current receiver
                                        var sig = pd.msignature.resolve_for(mclassdef.mclass.mclass_type, mclassdef.bound_mtype, mclassdef.mmodule, false)
-                                       # Because the last parameter of setters is never default, try to default them for the autoinit.
-                                       for param in sig.mparameters do
-                                               if not param.is_default and param.mtype isa MNullableType then
-                                                       param = new MParameter(param.name, param.mtype, param.is_vararg, true)
-                                               end
-                                               mparameters.add(param)
-                                       end
+                                       mparameters.add_all(sig.mparameters)
                                else
                                        # TODO attributes?
                                        abort
@@ -954,13 +948,7 @@ redef class AMethPropdef
 
                var mparameters = new Array[MParameter]
                for i in [0..param_names.length[ do
-                       var is_default = false
-                       if vararg_rank == -1 and param_types[i] isa MNullableType then
-                               if i < param_names.length-1 or accept_special_last_parameter then
-                                       is_default = true
-                               end
-                       end
-                       var mparameter = new MParameter(param_names[i], param_types[i], i == vararg_rank, is_default)
+                       var mparameter = new MParameter(param_names[i], param_types[i], i == vararg_rank)
                        if nsig != null then nsig.n_params[i].mparameter = mparameter
                        mparameters.add(mparameter)
                end
@@ -1408,7 +1396,7 @@ redef class AAttrPropdef
                if mwritepropdef != null then
                        var name: String
                        name = n_id2.text
-                       var mparameter = new MParameter(name, mtype, false, false)
+                       var mparameter = new MParameter(name, mtype, false)
                        var msignature = new MSignature([mparameter], null)
                        mwritepropdef.msignature = msignature
                end
index 5e28695..79799e8 100644 (file)
@@ -845,7 +845,6 @@ class NeoModel
                node.labels.add "MParameter"
                node["name"] = mparameter.name
                node["is_vararg"] = mparameter.is_vararg
-               node["is_default"] = mparameter.is_default
                node.out_edges.add(new NeoEdge(node, "TYPE", to_node(mparameter.mtype)))
                return node
        end
@@ -861,8 +860,7 @@ class NeoModel
                var name = node["name"].to_s
                var mtype = to_mtype(model, node.out_nodes("TYPE").first)
                var is_vararg = node["is_vararg"].as(Bool)
-               var is_default = node["is_default"].as(Bool)
-               var mparameter = new MParameter(name, mtype, is_vararg, is_default)
+               var mparameter = new MParameter(name, mtype, is_vararg)
                mentities[node.id.as(Int)] = mparameter
                return mparameter
        end
index 41d2058..b5f5d0c 100644 (file)
@@ -414,26 +414,30 @@ private class TypeVisitor
                                return null
                        end
                else if args.length != msignature.arity then
-                       if msignature.arity == msignature.min_arity then
-                               modelbuilder.error(node, "Error: expected {msignature.arity} argument(s) for `{mproperty}{msignature}`; got {args.length}. See introduction at `{mproperty.full_name}`.")
-                               return null
-                       end
+                       # Too much argument
                        if args.length > msignature.arity then
-                               modelbuilder.error(node, "Error: expected at most {msignature.arity} argument(s) for `{mproperty}{msignature}`; got {args.length}. See introduction at `{mproperty.full_name}`.")
-                               return null
-                       end
-                       if args.length < msignature.min_arity then
-                               modelbuilder.error(node, "Error: expected at least {msignature.min_arity} argument(s) for `{mproperty}{msignature}`; got {args.length}. See introduction at `{mproperty.full_name}`.")
+                               modelbuilder.error(node, "Error: expected {msignature.arity} argument(s) for `{mproperty}{msignature}`; got {args.length}. See introduction at `{mproperty.full_name}`.")
                                return null
                        end
+                       # Other cases are managed later
                end
 
+
                #debug("CALL {unsafe_type}.{msignature}")
 
                # Associate each parameter to a position in the arguments
                var map = new SignatureMap
 
-               var setted = args.length - msignature.min_arity
+               # Special case for the isolated last argument
+               # TODO: reify this method characteristics (where? the param, the signature, the method?)
+               var last_is_padded = mproperty.name.chars.last == '='
+               var nbargs = args.length
+               if last_is_padded then
+                       nbargs -= 1
+                       assert not args.last isa ANamedargExpr
+                       map.map[msignature.arity - 1] = args.length - 1
+                       self.visit_expr_subtype(args.last, msignature.mparameters.last.mtype)
+               end
 
                # First, handle named arguments
                for i in [0..args.length[ do
@@ -445,10 +449,6 @@ private class TypeVisitor
                                modelbuilder.error(e.n_id, "Error: no parameter `{name}` for `{mproperty}{msignature}`.")
                                return null
                        end
-                       if not param.is_default then
-                               modelbuilder.error(e, "Error: parameter `{name}` is not optional for `{mproperty}{msignature}`.")
-                               return null
-                       end
                        var idx = msignature.mparameters.index_of(param)
                        var prev = map.map.get_or_null(idx)
                        if prev != null then
@@ -456,10 +456,12 @@ private class TypeVisitor
                                return null
                        end
                        map.map[idx] = i
-                       setted -= 1
                        e.mtype = self.visit_expr_subtype(e.n_expr, param.mtype)
                end
 
+               # Number of minimum mandatory remaining parameters
+               var min_arity = 0
+
                # Second, associate remaining parameters
                var vararg_decl = args.length - msignature.arity
                var j = 0
@@ -468,16 +470,16 @@ private class TypeVisitor
                        if map.map.has_key(i) then continue
 
                        var param = msignature.mparameters[i]
-                       if param.is_default then
-                               if setted > 0 then
-                                       setted -= 1
-                               else
-                                       continue
-                               end
-                       end
 
                        # Search the next free argument: skip named arguments since they are already associated
-                       while args[j] isa ANamedargExpr do j += 1
+                       while j < nbargs and args[j] isa ANamedargExpr do j += 1
+                       if j >= nbargs then
+                               if not param.mtype isa MNullableType then
+                                       min_arity = j + 1
+                               end
+                               j += 1
+                               continue
+                       end
                        var arg = args[j]
                        map.map[i] = j
                        j += 1
@@ -491,6 +493,16 @@ private class TypeVisitor
                        self.visit_expr_subtype(arg, paramtype)
                end
 
+               if min_arity > 0 then
+                       if last_is_padded then min_arity += 1
+                       if min_arity < msignature.arity then
+                               modelbuilder.error(node, "Error: expected at least {min_arity} argument(s) for `{mproperty}{msignature}`; got {args.length}. See introduction at `{mproperty.full_name}`.")
+                       else
+                               modelbuilder.error(node, "Error: expected {min_arity} argument(s) for `{mproperty}{msignature}`; got {args.length}. See introduction at `{mproperty.full_name}`.")
+                       end
+                       return null
+               end
+
                # Third, check varargs
                if vararg_rank >= 0 then
                        var paramtype = msignature.mparameters[vararg_rank].mtype
index 2d1af37..d4de4ed 100644 (file)
@@ -80,8 +80,8 @@ var x
 
 #alt1#a.foo
 #alt1#a.foo(2)
-a.foo(1,2)
-a.foo(1,2,3)
+#alt1#a.foo(1,2)
+#alt1#a.foo(1,2,3)
 a.foo(1,2,3,4)
 a.foo(1,2,3,4,5)
 a.foo(1,2,3,4,5,6)
index 6ea74cf..f5f4622 100644 (file)
@@ -71,11 +71,11 @@ a.foo
 #alt1#a = new B(1)
 #alt1#a.foo
 
-a = new B(1,4)
-a.foo
+#alt1#a = new B(1,4)
+#alt1#a.foo
 
-a = new B(1,2,4)
-a.foo
+#alt1#a = new B(1,2,4)
+#alt1#a.foo
 
 a = new B(1,2,3,4)
 a.foo
@@ -86,8 +86,8 @@ a.foo
 #alt1#a = new C(1)
 #alt1#a.foo
 
-a = new C(4,1)
-a.foo
+#alt1#a = new C(4,1)
+#alt1#a.foo
 
 a = new C(3,4,1)
 a.foo
index a584add..e82ca07 100644 (file)
 import base_arg_default
 
 var a = new A
+a.foo(a=1,b=2,c=3,d=4,e=5,f=6)
 a.foo(a=1,b=2,3,4,e=5,f=6)
 a.foo(f=6,3,e=5,b=2,4,a=1)
-a.foo(3,e=5,b=2,4)
+a.foo(f=6,d=4,e=5,b=2,c=3,a=1)
+#alt1#a.foo(3,e=5,b=2,4)
 
 a.bar
 
@@ -43,4 +45,3 @@ a.bar(b=2,a=1,c=3)
 #alt1#a.bar(2,a=1,3, 4)
 #alt1#a.bar(fail=1)
 #alt1#a.bar(a=1,a=1)
-#alt1#a.foo(c=1,d=1)
index 22f62f0..76d8ce1 100644 (file)
@@ -26,9 +26,9 @@ end
 var a = new A #alt1# var a = new B
 a.foo(a=1,b=2,3,4,e=5,f=6)
 a.foo(f=6,3,e=5,b=2,4,a=1)
-a.foo(3,e=5,b=2,4)
+#alt3#a.foo(3,e=5,b=2,4)
 
 var b = new B #alt1# var b = new A
 b.foo(x=1,y=2,3,4,u=5,v=6)
 b.foo(v=6,3,u=5,y=2,4,x=1)
-b.foo(3,u=5,y=2,4)
+#alt3#b.foo(3,u=5,y=2,4)
index a948eeb..9558e13 100644 (file)
@@ -33,10 +33,10 @@ end
 
 var a = new A
 a.foo(order(1),order(2),order(3),order(4),order(5),order(6))
+a.foo(a=order(1),b=order(2),c=order(3),d=order(4),e=order(5),f=order(6))
 a.foo(a=order(1),b=order(2),order(3),order(4),e=order(5),f=order(6))
 a.foo(f=order(6),order(3),e=order(5),b=order(2),order(4),a=order(1))
-a.foo(order(3),e=order(5),b=order(2),order(4))
-a.foo(order(3),order(4))
+a.foo(f=order(6),d=order(4),e=order(5),b=order(2),c=order(3),a=order(1))
 
 bar(order(1),order(2),order(3))
 bar(order(1),order(2),order(3),order(4))
index 61ea614..56ee59c 100644 (file)
@@ -1,17 +1,3 @@
-
-
-1
-2
-
-
--
-1
-
-2
-3
-
-
--
 1
 2
 3
index fba2f2b..40dd13d 100644 (file)
@@ -1,6 +1,8 @@
-alt/base_arg_default_alt1.nit:81,3--5: Error: expected at least 2 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 0. See introduction at `base_arg_default_alt1::A::foo`.
-alt/base_arg_default_alt1.nit:82,3--5: Error: expected at least 2 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 1. See introduction at `base_arg_default_alt1::A::foo`.
-alt/base_arg_default_alt1.nit:88,3--5: Error: expected at most 6 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 7. See introduction at `base_arg_default_alt1::A::foo`.
-alt/base_arg_default_alt1.nit:94,3--5: Error: expected at most 3 argument(s) for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default_alt1::A::bar`.
-alt/base_arg_default_alt1.nit:99,3--5: Error: expected at most 3 argument(s) for `bar=(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default_alt1::A::bar=`.
-alt/base_arg_default_alt1.nit:110,1--13: Error: expected at most 3 argument(s) for `[]=(a: nullable Int, b: nullable Int, c: nullable Int): Int`; got 4. See introduction at `base_arg_default_alt1::A::[]=`.
+alt/base_arg_default_alt1.nit:81,3--5: Error: expected at least 4 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 0. See introduction at `base_arg_default_alt1::A::foo`.
+alt/base_arg_default_alt1.nit:82,3--5: Error: expected at least 4 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 1. See introduction at `base_arg_default_alt1::A::foo`.
+alt/base_arg_default_alt1.nit:83,3--5: Error: expected at least 4 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 2. See introduction at `base_arg_default_alt1::A::foo`.
+alt/base_arg_default_alt1.nit:84,3--5: Error: expected at least 4 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 3. See introduction at `base_arg_default_alt1::A::foo`.
+alt/base_arg_default_alt1.nit:88,3--5: Error: expected 6 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 7. See introduction at `base_arg_default_alt1::A::foo`.
+alt/base_arg_default_alt1.nit:94,3--5: Error: expected 3 argument(s) for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default_alt1::A::bar`.
+alt/base_arg_default_alt1.nit:99,3--5: Error: expected 3 argument(s) for `bar=(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default_alt1::A::bar=`.
+alt/base_arg_default_alt1.nit:110,1--13: Error: expected 3 argument(s) for `[]=(a: nullable Int, b: nullable Int, c: nullable Int): Int`; got 4. See introduction at `base_arg_default_alt1::A::[]=`.
index 437e8ee..289d97c 100644 (file)
@@ -6,26 +6,11 @@
 2
 -
 1
-4
--
-1
-2
-4
--
-1
 2
 3
 4
 -
 1
  
-4
--
-1
 3
 4
index cdf6690..ccec709 100644 (file)
@@ -1,6 +1,9 @@
 alt/base_arg_default_autoinit_alt1.nit:59,5--7: Error: expected at least 1 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 0. See introduction at `standard::Object::init`.
-alt/base_arg_default_autoinit_alt1.nit:68,5--7: Error: expected at most 2 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 3. See introduction at `standard::Object::init`.
-alt/base_arg_default_autoinit_alt1.nit:71,5--7: Error: expected at least 2 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 1. See introduction at `standard::Object::init`.
-alt/base_arg_default_autoinit_alt1.nit:83,5--7: Error: expected at most 4 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 5. See introduction at `standard::Object::init`.
-alt/base_arg_default_autoinit_alt1.nit:86,5--7: Error: expected at least 2 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 1. See introduction at `standard::Object::init`.
-alt/base_arg_default_autoinit_alt1.nit:95,5--7: Error: expected at most 3 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 4. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:68,5--7: Error: expected 2 argument(s) for `init(mandatory: Int, optional: nullable Int)`; got 3. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:71,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 1. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:74,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 2. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:77,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 3. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:83,5--7: Error: expected 4 argument(s) for `init(mandatory: Int, optional: nullable Int, optional_b: nullable Int, mandatory_b: Int)`; got 5. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:86,5--7: Error: expected 3 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 1. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:89,5--7: Error: expected 3 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 2. See introduction at `standard::Object::init`.
+alt/base_arg_default_autoinit_alt1.nit:95,5--7: Error: expected 3 argument(s) for `init(optional_b: nullable Int, mandatory_b: Int, mandatory: Int)`; got 4. See introduction at `standard::Object::init`.
index be2e49f..f31da85 100644 (file)
 5
 6
 -
-
+1
 2
 3
 4
 5
-
+6
+-
+1
+2
+3
+4
+5
+6
 -
 
 
index f41b60a..39b6ba4 100644 (file)
@@ -1,4 +1,4 @@
-alt/base_arg_named_alt1.nit:43,3--5: Error: expected at most 3 argument(s) for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default::A::bar`.
-alt/base_arg_named_alt1.nit:44,7--10: Error: no parameter `fail` for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`.
-alt/base_arg_named_alt1.nit:45,11--13: Error: parameter `a` already associated with argument #0 for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`.
-alt/base_arg_named_alt1.nit:46,7--9: Error: parameter `c` is not optional for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`.
+alt/base_arg_named_alt1.nit:22,3--5: Error: expected at least 5 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 4. See introduction at `base_arg_default::A::foo`.
+alt/base_arg_named_alt1.nit:45,3--5: Error: expected 3 argument(s) for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`; got 4. See introduction at `base_arg_default::A::bar`.
+alt/base_arg_named_alt1.nit:46,7--10: Error: no parameter `fail` for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`.
+alt/base_arg_named_alt1.nit:47,11--13: Error: parameter `a` already associated with argument #0 for `bar(a: nullable Int, b: nullable Int, c: nullable Int)`.
index 17a46de..6be7ca2 100644 (file)
 5
 6
 -
-
-2
-3
-4
-5
-
--
 1
 2
 3
 5
 6
 -
-
-2
-3
-4
-5
-
--
index aa69f50..20528d9 100644 (file)
@@ -1,6 +1,4 @@
 alt/base_arg_named_inherit_alt1.nit:27,7: Error: no parameter `a` for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`.
 alt/base_arg_named_inherit_alt1.nit:28,7: Error: no parameter `f` for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`.
-alt/base_arg_named_inherit_alt1.nit:29,9: Error: no parameter `e` for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`.
 alt/base_arg_named_inherit_alt1.nit:32,7: Error: no parameter `x` for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`.
 alt/base_arg_named_inherit_alt1.nit:33,7: Error: no parameter `v` for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`.
-alt/base_arg_named_inherit_alt1.nit:34,9: Error: no parameter `u` for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`.
index 2a85022..29bba0d 100644 (file)
@@ -1,3 +1,2 @@
 alt/base_arg_named_inherit_alt2.nit:27,7: Error: no parameter `a` for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`.
 alt/base_arg_named_inherit_alt2.nit:28,7: Error: no parameter `f` for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`.
-alt/base_arg_named_inherit_alt2.nit:29,9: Error: no parameter `e` for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`.
diff --git a/tests/sav/base_arg_named_inherit_alt3.res b/tests/sav/base_arg_named_inherit_alt3.res
new file mode 100644 (file)
index 0000000..46dfc27
--- /dev/null
@@ -0,0 +1,2 @@
+alt/base_arg_named_inherit_alt3.nit:29,3--5: Error: expected at least 5 argument(s) for `foo(a: nullable Int, b: nullable Int, c: Int, d: Int, e: nullable Int, f: nullable Int)`; got 4. See introduction at `base_arg_default::A::foo`.
+alt/base_arg_named_inherit_alt3.nit:34,3--5: Error: expected at least 5 argument(s) for `foo(x: nullable Int, y: nullable Int, z: Int, t: Int, u: nullable Int, v: nullable Int)`; got 4. See introduction at `base_arg_default::A::foo`.
index b16bf3f..7ed6845 100644 (file)
 5
 6
 -
->6
->3
->5
+>1
 >2
+>3
 >4
->1
+>5
+>6
 1
 2
 3
 5
 6
 -
+>6
 >3
 >5
 >2
 >4
-
+>1
+1
 2
 3
 4
 5
-
+6
 -
->3
+>6
 >4
-
-
+>5
+>2
+>3
+>1
+1
+2
 3
 4
-
-
+5
+6
 -
 >1
 >2