Scope for default values in a primary constructor #3170
Labels
brevity
A feature whose purpose is to enable concise syntax, typically expressible already in a longer form
primary-constructors
The primary constructors proposal (#3023) defines the scope that the default values are evaluated in as:
Then it goes on to define a careful renaming to ensure that the desugared constructor inside the class body doesn't accidentally refer to an identified that is shadowed by a class member.
Is there a reason for this choice? Given that the primary constructor does end up being a generative constructor on the class, and is syntactically very similar to a constructor declaration, it seems most intuitive to me for it to have the same default value scope as other constructors do: the class scope.
I acknowledge that it's a little weird for a primary constructor's default values to be able to refer to class members when it textually appears before the class's
{
. But that doesn't seem any weirder to me than:I think having the same scope will also make it easier for users and automated refactoring tooling to convert primary constructors to body constructors and vice versa.
The text was updated successfully, but these errors were encountered: