nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
238 stars 64 forks source link

Simplify constructors: next episode #2803

Closed Delja closed 4 years ago

Delja commented 4 years ago

The current constructors are quite complex, that is why Jean Privat had proposed to simplify them with the pr #1966.

The current init has a double facet, internal with a signature and an empty body and an external one with a signature and initializer represent the attributes to initialize.

This pr replace the external facet by introducing a new constructor defaultinit specific to each class. This default property includes the orchestration of initializers (non-default attributes, autoinit methods, and autoinit annotation in the class). In addition, this property is now the one exposed when a new A is executed.

The current init used to manually set the default constructor it's used to perform a processing after initialization. Note this one must have an empty signature. If this is not the case, an error will be generated.

To use the init in a similar way, we now have to use the old_style_init annotation.

This pr resolve minor bugs and test issues of the Jean's pr .

Louis-Vincent commented 4 years ago

@Delja Dans le fichier abstract_compiler la redef de AClassdef, à quelle occasion is_calling_init serait vrai? Les initialiseurs ne sont elles pas juste des méthodes qui assigne une valeur à un attribut? Je vois pas le lien entre les initialiseurs et is_calling_init