-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for nominal records #44774
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2927,36 +2927,39 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde | |
} | ||
} | ||
|
||
if (paramList is null) | ||
if (paramList is null && !_declModifiers.HasFlag(DeclarationModifiers.Data)) | ||
{ | ||
if (_declModifiers.HasFlag(DeclarationModifiers.Data)) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_BadRecordDeclaration, declaration.NameLocations[0]); | ||
} | ||
// Not a record | ||
return; | ||
} | ||
|
||
if (paramList.ParameterCount == 0 || !_declModifiers.HasFlag(DeclarationModifiers.Data)) | ||
{ | ||
// PROTOTYPE: The semantics of an empty parameter list have not been decided. Error | ||
// for now | ||
diagnostics.Add(ErrorCode.ERR_BadRecordDeclaration, paramList.Location); | ||
} | ||
|
||
BinderFactory binderFactory = this.DeclaringCompilation.GetBinderFactory(paramList.SyntaxTree); | ||
var binder = binderFactory.GetBinder(paramList); | ||
|
||
// PROTOTYPE: need to check base members as well | ||
var memberSignatures = s_duplicateMemberSignatureDictionary.Allocate(); | ||
foreach (var member in members) | ||
{ | ||
memberSignatures.Add(member, member); | ||
} | ||
|
||
var ctor = addCtor(paramList); | ||
// Positional record | ||
if (!(paramList is null)) | ||
{ | ||
// PROTOTYPE: The semantics of an empty parameter list have not been decided. Error | ||
// for now | ||
if (paramList.ParameterCount == 0 || !_declModifiers.HasFlag(DeclarationModifiers.Data)) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_BadRecordDeclaration, paramList.Location); | ||
} | ||
|
||
BinderFactory binderFactory = this.DeclaringCompilation.GetBinderFactory(paramList.SyntaxTree); | ||
var binder = binderFactory.GetBinder(paramList); | ||
|
||
var ctor = addCtor(binder, paramList); | ||
addProperties(ctor.Parameters); | ||
} | ||
|
||
addCopyCtor(); | ||
addCloneMethod(); | ||
addProperties(ctor.Parameters); | ||
|
||
var thisEquals = addThisEquals(); | ||
addObjectEquals(thisEquals); | ||
addHashCode(); | ||
|
@@ -2965,7 +2968,7 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde | |
|
||
return; | ||
|
||
SynthesizedRecordConstructor addCtor(ParameterListSyntax paramList) | ||
SynthesizedRecordConstructor addCtor(Binder binder, ParameterListSyntax paramList) | ||
{ | ||
var ctor = new SynthesizedRecordConstructor(this, binder, paramList, diagnostics); | ||
if (!memberSignatures.ContainsKey(ctor)) | ||
|
@@ -3000,7 +3003,7 @@ void addCloneMethod() | |
|
||
void addProperties(ImmutableArray<ParameterSymbol> recordParameters) | ||
{ | ||
foreach (ParameterSymbol param in ctor.Parameters) | ||
foreach (ParameterSymbol param in recordParameters) | ||
{ | ||
var property = new SynthesizedRecordPropertySymbol(this, param, diagnostics); | ||
if (!memberSignatures.ContainsKey(property)) | ||
|
@@ -3063,8 +3066,12 @@ private void AddSynthesizedConstructorsIfNecessary(ArrayBuilder<Symbol> members, | |
switch (method.MethodKind) | ||
{ | ||
case MethodKind.Constructor: | ||
hasInstanceConstructor = true; | ||
hasParameterlessInstanceConstructor = hasParameterlessInstanceConstructor || method.ParameterCount == 0; | ||
// Ignore the record copy constructor | ||
if (!(method is SynthesizedRecordCopyCtor)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we check 'method.IsImplicitlyDeclared' here instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true for all SynthesizedInstanceMethodSymbols, including the record primary constructor, unfortunately |
||
{ | ||
hasInstanceConstructor = true; | ||
hasParameterlessInstanceConstructor = hasParameterlessInstanceConstructor || method.ParameterCount == 0; | ||
} | ||
break; | ||
|
||
case MethodKind.StaticConstructor: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: positional members?