-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rudimentary support for constructors #27
Comments
As of now, this feature is implemented. In part due to a lack of a typed desugaring step, the feature is lacking in at least two areas:
@EliasC is adding an additional desugaring step to run after typing in which we will be able to optimise the init call to use ! where appropriate. Until then, I am leaving this ticket open. |
@EliasC what is the status of this? |
@TobiasWrigstad There is a typed desugaring step in the compiler (called |
Please do but don't stress to finish. As long as there is clear ownership etc. |
It would be nice to see some text about constructors in the manual. |
@supercooldave Added a bit under Active/Passive Classes and incorporated it in the examples |
Constructors are really tricky to get right, and there are many many issues such as leaking of this before an object has been fully initialised etc. This is clearly important for any PL project, but for the moment, I believe it is not so important to get it "right from the start".
I have written many lines like this:
and it makes me sad each time. For now, I propose that we give special status to methods named
init
in that we allow them to be called directly on object creation. I propose that we support the following syntactic sugarwhich is desugared into
This keeps init a normal method in all other respects, i.e., its return type can be void or anything, and it can be called at any point. A more general approach would be to allow something like
for some syntax like that to remove the special status of
init
, but we want to move in the direction of constructors in the future, so I'd rather have a very specific temporary feature than one which may actually be missed in the future.The text was updated successfully, but these errors were encountered: