> De: "Brian Goetz" <[email protected]>
> À: "Tagir Valeev" <[email protected]>, "Remi Forax" <[email protected]>
> Cc: "amber-spec-experts" <[email protected]>
> Envoyé: Jeudi 5 Septembre 2019 23:26:34
> Objet: Re: Draft JLS spec for records

>> I don't think so. A compact constructor (or require initializer, as you 
>> propose)
>> could be not the only constructor. An instance initializer is convenient
>> because it's added to every constructor, regardless of whether it's compact 
>> or
>> not. So the new thing doesn't supersede the instance initializer and I see no
>> good reason to explicitly disable it.

> Vicente offered another reason why we might want to prohibit the instance
> initializer, if only out of expediency; it complicates the analysis of which
> fields are DA on all paths through the constructor (and therefore, do not need
> to be automatically initialized.) If you have a record:

> record Foo(int i) {
> { this.i = 0; }
> }

> then the canonical constructor has to see that `i` is always initialized by 
> the
> static init, and therefore should be not initialized. Worse, if we have:

> record Foo(int i) {
> { if (tuesday) this.i = 0; }
> }

> then we have to issue a compilation error, since we have fields that are 
> neither
> DA nor DU at the end of the initializer.

> None of this is impossible to do, of course; it's just not clear whether it's
> worth it, given the limited utility of instance initializers in records
> (because we've already banned instance fields.)

If we want to fix that with an the analysis, it will have to work on 
user-written code mixed with generated code, 
it doesn't seem to be a good idea. 

so it's Ok to not support instance initializers in record. 

Rémi 

Reply via email to