Merge: New constructors with the `new` keyword
authorJean Privat <jean@pryen.org>
Fri, 24 Oct 2014 23:58:38 +0000 (19:58 -0400)
committerJean Privat <jean@pryen.org>
Fri, 24 Oct 2014 23:58:38 +0000 (19:58 -0400)
commite71e1df0044bd87482f616cc30463e5567297d5e
tree3a55fe80c8235d0676db7ae6d5b31d8271996586
parentdcf916fdf80ffb2f300607180943a3e20350a508
parent45621a68da397d96b5d9229bd133ea414c6dd540
Merge: New constructors with the `new` keyword

`new` constructors where introduced with the FFI and generalized latter for intern methods.
This PR make them also legal with used-defined code in Nit.

~~~
abstract class Person
   var age: Int
   new(age: Int) do
      if i < 18 then
         return new Adult(age)
      else
         return new Child(age)
      end
end
~~~

A `new` constructor is specified like a static method.
By default it returns the type of self, but this can be changed by the user.

This PR starts by generalizing the `new` constructors. Thus a lot of specific code in engine is removed.
Then additional rules are added to control the usage of user-defined `new` constructors.

The original code was great enough to accepts these new kind of method without heavy modification.

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