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>

1  2 
src/semantize/typing.nit

Simple merge