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

Minor refactoring in 'required' handling for override completion #62422

Merged
merged 1 commit into from
Jul 6, 2022
Merged
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 @@ -76,7 +76,7 @@ public override TResult Accept<TArgument, TResult>(SymbolVisitor<TArgument, TRes

public bool IsWriteOnly => this.GetMethod == null && this.SetMethod != null;

public bool IsRequired => Modifiers.IsRequired;
public bool IsRequired => Modifiers.IsRequired && !IsIndexer;

public new IPropertySymbol OriginalDefinition => this;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,6 @@ public static async Task<IPropertySymbol> OverridePropertyAsync(
codeFactory.IdentifierName("value")));
}

// The user can add required if they want, but if the property being overridden is required, this one needs to be as well.
modifiers = modifiers.WithIsRequired(overriddenProperty.IsIndexer
? false
: (modifiers.IsRequired || overriddenProperty.IsRequired));
Comment on lines -412 to -415
Copy link
Member Author

@Youssef1313 Youssef1313 Jul 6, 2022

Choose a reason for hiding this comment

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

The indexer part is now done in CodeGenerationPropertySymbol, and the required modifier now no longer needs to be special cased here. It'll flow automatically from GetOverrideModifiers. If new modifiers are added in the future, they can just flow automatically via GetOverrideModifiers as well, instead of keeping special cases


// Only generate a getter if the base getter is accessible.
IMethodSymbol? accessorGet = null;
if (overriddenProperty.GetMethod != null && overriddenProperty.GetMethod.IsAccessibleWithin(containingType))
Expand Down Expand Up @@ -473,10 +468,10 @@ public static async Task<ISymbol> OverrideAsync(
ISymbol symbol,
INamedTypeSymbol containingType,
Document document,
DeclarationModifiers? declarationModifiers = null,
DeclarationModifiers extraDeclarationModifiers = default,
CancellationToken cancellationToken = default)
{
var modifiers = declarationModifiers ?? GetOverrideModifiers(symbol);
var modifiers = GetOverrideModifiers(symbol) + extraDeclarationModifiers;

if (symbol is IMethodSymbol method)
{
Expand Down