implementation of record constructor auto-initialization [was Re: instance initializer]
Brian Goetz
brian.goetz at oracle.com
Fri Sep 6 15:11:30 UTC 2019
Given than most users don’t even realize you can say `return` in a constructor, this seems a reasonable restriction. The whole point of a compact ctor is to NOT have to specify the field initialization.
> On Sep 6, 2019, at 10:53 AM, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>
>
> On 06/09/2019 15:45, Brian Goetz wrote:
>>>
>>> Actually - not sure - what do you mean by "exit path"? We clearly can't have "returns" here. And, if we "throw" then we don't care much about initializing.
>>>
>>>
>>
>> Returns are exactly what I was concerned about; currently return is allowed, though weird, in ctors.
>>
>> If you want to say “no return in compact ctor”, that’s a reasonable simplification (though we’ll battle this beast again later when we want to expand some of the compact-ctor goodies to more general class constructors.)
>>
> I think I'd slightly prefer it to restrict it that way - not out of compiler complexity (as I said, a try/catch should be enough to handle it) - but out of managing user expectations.
>
> Maurizio
>
More information about the amber-dev
mailing list