[nem-en] closure in ctor, this in ctor

Kamil Skalski kamil.skalski at gmail.com
Mon Mar 26 23:13:50 CEST 2007


2007/3/26, Dmitry Ivankov <divanorama at gmail.com>:
> I'm working on field init & base/other ctor calls.

That's great! :-)

> And field init will happen before base ctor call.
> But when closure utilizing "this" is created we require that ctor starts
> with "base(..)", it'll be too strict if there are field-inits (we generate
> unnecessary error in that case).

We are only limited by what code verifies properly. Otherwise we
should allow as much usage of 'this' as possible.


>
> So, will it be okay to move
> "_N_closure._N__N_closurised_this_ptr999 = this" exactly
> after base/other ctor call wherever it is?

I see no problem with that - closurised_this will be used only during
invocation of local functions - so it does not need to be initialized
very early. Assuming you won't "overlook" any local function call,
then it should be ok.

>
> And a more general question: how is the status of "this" changed in
> ctor/what are restrictions on it?
> Before base ctor call:
> - can't access base
>  - can assign own fields some values
>  - (?) can use already assigned values via "this.field1"
> - (?) can use default-initialized fields (null, 0, ...)

I guess all this should be allowed (if possible). I think that also
using uninitialized fields might be good to have... actually, they are
null/0 initialized.

> - can't use "this", except in "this.not_base_field"

Do you allow virtual calls before base call? Is it possible at all (verifies)?

> After base ctor call:
> - treat "this" as fully constructed object, i.e. use "this" in any way
> And the most tricky, during the base call:
> a) while computing params to base ctor (maybe important if we want to pass
> "this" to base ctor)
> - same as before base ctor

I think the base call's params issue can be easily reduced to the same
problem as using 'this' before base call. You just need to pass flags
properly to check this. So, it should allow / forbid exactly the same
things.

> b) in base ctor (important if base ctor calls virtual method)
> - (?) become fully constructed exactly when base is fully constructed

I don't quite get what do you exactly mean. Isn't it just the same
case as in normal constructor? After ctor's base is called and
initializers run, it is fully constructed.


>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
>


-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list