Skip to content
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

EnC: allow changing accessibility of members #75191

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1200,10 +1200,10 @@ newContainingMemberOrType is IPropertySymbol newPropertySymbol &&
// int P => expr;
// int P { get => expr; } = init
//
// Note: An update of a partial property/indexer definition can only affect its attributes. The partial definition does not have a body.
// In that case we do not need to update/analyze the accessors since attribute update has no impact on them.
// Note: An update of a partial property/indexer definition can only affect its attributes and accessibility. The partial definition does not have a body.
// In that case we do not need to update/analyze the accessors since attribute/accessibility update has no impact on them.
//
// 2) Property/indexer declarations differ in readonly keyword.
// 2) Property/indexer declarations differ in readonly keyword or accessibility.
// 3) Property signature changes
// 4) Property name changes

Expand All @@ -1216,7 +1216,7 @@ newContainingMemberOrType is IPropertySymbol newPropertySymbol &&
{
if (oldHasExpressionBody ||
newHasExpressionBody ||
DiffersInReadOnlyModifier(oldPropertySymbol.GetMethod, newPropertySymbol.GetMethod) ||
DiffersInReadOnlyOrAccessibilityModifiers(oldPropertySymbol.GetMethod, newPropertySymbol.GetMethod) ||
IsMemberOrDelegateReplaced(oldPropertySymbol, newPropertySymbol))
{
result.Add((oldPropertySymbol.GetMethod, newPropertySymbol.GetMethod, editKind));
Expand All @@ -1225,7 +1225,7 @@ newContainingMemberOrType is IPropertySymbol newPropertySymbol &&

if (oldPropertySymbol.SetMethod != null || newPropertySymbol.SetMethod != null)
{
if (DiffersInReadOnlyModifier(oldPropertySymbol.SetMethod, newPropertySymbol.SetMethod) ||
if (DiffersInReadOnlyOrAccessibilityModifiers(oldPropertySymbol.SetMethod, newPropertySymbol.SetMethod) ||
IsMemberOrDelegateReplaced(oldPropertySymbol, newPropertySymbol))
{
result.Add((oldPropertySymbol.SetMethod, newPropertySymbol.SetMethod, editKind));
Expand All @@ -1237,15 +1237,15 @@ newContainingMemberOrType is IPropertySymbol newPropertySymbol &&

if (oldSymbol is IEventSymbol oldEventSymbol && newSymbol is IEventSymbol newEventSymbol)
{
// 1) Event declarations differ in readonly keyword.
// 1) Event declarations differ in readonly keyword or accessibility.
// 2) Event signature changes
// 3) Event name changes

result.Add((oldEventSymbol, newEventSymbol, editKind));

if (oldEventSymbol.AddMethod != null || newEventSymbol.AddMethod != null)
{
if (DiffersInReadOnlyModifier(oldEventSymbol.AddMethod, newEventSymbol.AddMethod) ||
if (DiffersInReadOnlyOrAccessibilityModifiers(oldEventSymbol.AddMethod, newEventSymbol.AddMethod) ||
IsMemberOrDelegateReplaced(oldEventSymbol, newEventSymbol))
{
result.Add((oldEventSymbol.AddMethod, newEventSymbol.AddMethod, editKind));
Expand All @@ -1254,7 +1254,7 @@ newContainingMemberOrType is IPropertySymbol newPropertySymbol &&

if (oldEventSymbol.RemoveMethod != null || newEventSymbol.RemoveMethod != null)
{
if (DiffersInReadOnlyModifier(oldEventSymbol.RemoveMethod, newEventSymbol.RemoveMethod) ||
if (DiffersInReadOnlyOrAccessibilityModifiers(oldEventSymbol.RemoveMethod, newEventSymbol.RemoveMethod) ||
IsMemberOrDelegateReplaced(oldEventSymbol, newEventSymbol))
{
result.Add((oldEventSymbol.RemoveMethod, newEventSymbol.RemoveMethod, editKind));
Expand All @@ -1264,8 +1264,10 @@ newContainingMemberOrType is IPropertySymbol newPropertySymbol &&
return;
}

static bool DiffersInReadOnlyModifier(IMethodSymbol? oldMethod, IMethodSymbol? newMethod)
=> oldMethod != null && newMethod != null && oldMethod.IsReadOnly != newMethod.IsReadOnly;
static bool DiffersInReadOnlyOrAccessibilityModifiers(IMethodSymbol? oldMethod, IMethodSymbol? newMethod)
=> oldMethod != null &&
newMethod != null &&
(oldMethod.IsReadOnly != newMethod.IsReadOnly || oldMethod.DeclaredAccessibility != newMethod.DeclaredAccessibility);

// Update to a type declaration with primary constructor may also need to update
// the primary constructor, copy-constructor and/or synthesized record auto-properties.
Expand Down
Loading
Loading