From e134bb7058e9848120b93b345f96d6ac0cb8c815 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 15 Jan 2020 16:40:26 -0800 Subject: [PATCH] Add spec work for record ctor (#3076) * Add spec work for record ctor * Add more detail about constructor implementation --- proposals/records-wip.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/proposals/records-wip.md b/proposals/records-wip.md index 1d8979e..296693e 100644 --- a/proposals/records-wip.md +++ b/proposals/records-wip.md @@ -13,7 +13,7 @@ class_declaration struct_declaration : attributes? struct_modifiers? 'partial'? 'struct' identifier type_parameter_list? - record_parameters? struct_interfaces? type_parameter_constraints_clauses? struct_body + parameter_list? struct_interfaces? type_parameter_constraints_clauses? struct_body ; class_body @@ -28,3 +28,35 @@ struct_body ``` The `attributes` non-terminal will also permit a new contextual attribute, `data`. + +A class (struct) declared with a parameter list or `data` modifier is called a record class (record struct), either of which is a record type. + +It is an error to declare a record type without both a parameter list and the `data` modifier. + +## Members of a record type + +In addition to the members declared in the class-body, a record type has the following additional members: + +### Primary Constructor + +A record type has a public constructor whose signature corresponds to the value parameters of the +type declaration. This is called the primary constructor for the type, and causes the implicitly +declared default constructor to be suppressed. If a constructor with the same signature is +already present in the class, the synthesized primary constructor is suppressed. +At runtime the primary constructor + +1. initializes compiler-generated backing fields for the properties corresponding to the value parameters (if these properties are compiler-provided; see [Synthesized properties](#Synthesized Properties)); then + +2. executes the instance field initializers appearing in the class-body; and then + invokes the base class constructor with no arguments. + +[ ] TODO: add base call syntax and specification about choosing base constructor through overload resolution + +### Properties + +For each record parameter of a record type declaration there is a corresponding public property member whose name and type are taken from the value parameter declaration. If no concrete (i.e. non-abstract) public property with a get accessor and with this name and type is explicitly declared or inherited, it is produced by the compiler as follows: + +For a record struct or a sealed record class: + +* A public get-only auto-property is created. Its value is initialized during construction with the value of the corresponding primary constructor parameter. Each "matching" inherited virtual property's get accessor is overridden. +