From: Jean Privat Date: Tue, 14 Apr 2015 09:33:32 +0000 (+0700) Subject: Merge: Intern new X-Git-Tag: v0.7.4~27 X-Git-Url: http://nitlanguage.org Merge: Intern new A small short PR that enables a `new`-factory to instantiate itself. previously there was no way to do that. The following code will stack-overflow: ~~~nit class A new do var res = new A res.do_thigns return res end end var a = new A # infinite recursion of `new A` ~~~ Note: this is a very bad example as what is done in the previous `new` should be done in an `init` instead since it is related to the initialization of the object. A `new` factory should be exclusively used for some factory-concern like returning a more specialized object or returning an already existing object. With this PR, the primitive constructor is available and is called `intern`, as the annotation that indicates things that cannot be programmed in Nit but are provided by the execution engine. So in the previous example, just use this primitive constructor instead of doing a recursive call: ~~~ var res = new A.intern ~~~ This intern constructor just do the allocation and the initialization of attributes with default values. `init` is not called. Maybe it should not do the initialization of attributes neither but if I skip them, there is no way for the programmer to ask for them manually. whereas `init` in not automatically called but can be called manually. note: this PR is a small step toward the conclusion of the constructor saga, more will come soon (I hope) Pull-Request: #1252 Reviewed-by: Alexis Laferrière --- 53029819839a48f83207f8238b1aeb4704f3bb1c