Merge: new annotation for manual setter `autoinit`
authorJean Privat <jean@pryen.org>
Tue, 30 Sep 2014 01:51:44 +0000 (21:51 -0400)
committerJean Privat <jean@pryen.org>
Tue, 30 Sep 2014 01:51:44 +0000 (21:51 -0400)
commit71dafe3024fb54db4460cedfe9cd28cdfd02dd9c
treefecfb82d76ffd9619e0f832aa2ad772a0bc0c20d
parent0c7475397468f8ea0679a53810f0437bfec2bf35
parent7db0691fd2764831d77876a9823c5a29160d516c
Merge: new annotation for manual setter `autoinit`

Sometime, automatic setters are not suitable and manual ones should be used.
Nit, especially since annotations (#601 and #604), has a simple way to have attributes and manual setters.

~~~niy
class A
   var foo: String is private writable(private_set_foo)
   fun foo=(v: String) do ...
end
~~~

However, with new constructor, it is the `private_set_foo` method that is used as initializer during the instantiation.

~~~nit
var a = new A("toto") # is in fact:
# a = alloc-instance(A)
# a.private_set_foo("toto")
# a.init
~~~

One may want to manually promote some setters as initializers, it is the job of the proposed `autoinit` annotation.

~~~nit
class B
   var foo: String is private writable(private_set_foo), noinit
   fun foo=(v: String) is autoinit do ...
end

var b = new B("toto") # is in fact:
# B = alloc-instance(B)
# b.foo=("toto")
# b.init
~~~

Bonus: in fact, this works for any method, even when they have more than one parameter. See the modification of the clock example that now use new constructors with a manually-set auto-initializer.

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