Skip to content

Disallow Clone members in source records#45775

Merged
jcouv merged 6 commits intodotnet:masterfrom
jcouv:block-clone
Jul 10, 2020
Merged

Disallow Clone members in source records#45775
jcouv merged 6 commits intodotnet:masterfrom
jcouv:block-clone

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Jul 8, 2020

Fixes #45591
Corresponding spec change: dotnet/csharplang#3652

@jcouv jcouv added this to the 16.8 milestone Jul 8, 2020
@jcouv jcouv self-assigned this Jul 8, 2020
@jcouv jcouv marked this pull request as ready for review July 8, 2020 07:22
@jcouv jcouv requested a review from a team as a code owner July 8, 2020 07:22
ERR_DoesNotOverrideMethodFromObject = 8869,
ERR_SealedGetHashCodeInRecord = 8870,
ERR_DoesNotOverrideBaseEquals = 8871,
ERR_CloneDisallowedInRecord = 8872,
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8872 [](start = 38, length = 4)

There is already a PR under review that uses numbers through 8874. Consider picking one of the next numbers and also leaving an empty line above this member to simplify merging process. #Closed

return;
}

Dictionary<string, ImmutableArray<Symbol>> membersByName = GetMembersByName();
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetMembersByName [](start = 71, length = 16)

Could we simply use GetMembers("Clone") and then iterate through the result? #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jul 8, 2020

Done with review pass (iteration 1) #Closed

Co-authored-by: Rikki Gibson <rikkigibson@gmail.com>
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 5)

var comp = CreateCompilationWithIL(src, il, options: TestOptions.DebugExe, parseOptions: TestOptions.RegularPreview);
comp.VerifyDiagnostics();
CompileAndVerify(comp, expectedOutput: "RAN");
// Note: we do load the Clone method from metadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an interesting case. What is the rationale for allowing this vs. marking this as an error in metadata import?

I don't necessarily think this is wrong but curious about the reasoning here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaredpar I'm open to revisiting. My rationale was:
(1) we're putting a restriction with the idea of lifting it in the future, it may not be worthwhile to be airtight to catch people who really go out of their way to do weird things.
(2) not knowing what the future design would be and whether it would require a new framework, I'm not sure we want to prevent the C# 9 compiler from using types produced by a future compiler (ie. that do have speakable Clone methods).

@jcouv
Copy link
Member Author

jcouv commented Jul 9, 2020

@dotnet/roslyn-compiler for a second review. Thanks

@jcouv jcouv merged commit bf301b0 into dotnet:master Jul 10, 2020
@ghost ghost modified the milestones: 16.8, Next Jul 10, 2020
@jcouv jcouv deleted the block-clone branch July 10, 2020 17:25
@alrz
Copy link
Member

alrz commented Jul 15, 2020

Was hoping to redeclare as Clone() => this; to be able to use with with non-immutable record-like types like ef entity models. This change makes it impossible to do that.. .

@jcouv
Copy link
Member Author

jcouv commented Jul 15, 2020

@alrz In the current design, with only uses the unspeakable clone method. It never uses the Clone() method and users can't customize it. We're considering how to do that post-C#9, which is why we're reserving members named "Clone" for now.

@JoeRobich JoeRobich modified the milestones: Next, 16.8.P1 Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Records: disallow declaring members with name "Clone"

6 participants