From: Jean Privat Date: Tue, 30 Sep 2014 01:51:44 +0000 (-0400) Subject: Merge: new annotation for manual setter `autoinit` X-Git-Tag: v0.6.9~8 X-Git-Url: http://nitlanguage.org 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 Reviewed-by: Alexandre Terrasa --- 71dafe3024fb54db4460cedfe9cd28cdfd02dd9c