Skip to content

Commit

Permalink
Field-backed properties: interface properties (#75219)
Browse files Browse the repository at this point in the history
  • Loading branch information
cston authored Sep 25, 2024
1 parent 2bb756e commit f1b2823
Show file tree
Hide file tree
Showing 4 changed files with 831 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static SourcePropertySymbol Create(
out _);

bool allowAutoPropertyAccessors = (modifiers & (DeclarationModifiers.Abstract | DeclarationModifiers.Extern | DeclarationModifiers.Indexer)) == 0 &&
(!containingType.IsInterface || (modifiers & DeclarationModifiers.Static) != 0) &&
(!containingType.IsInterface || hasGetAccessorImplementation || hasSetAccessorImplementation || (modifiers & DeclarationModifiers.Static) != 0) &&
((modifiers & DeclarationModifiers.Partial) == 0 || hasGetAccessorImplementation || hasSetAccessorImplementation);
bool hasAutoPropertyGet = allowAutoPropertyAccessors && getSyntax != null && !hasGetAccessorImplementation;
bool hasAutoPropertySet = allowAutoPropertyAccessors && setSyntax != null && !hasSetAccessorImplementation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,16 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions,
}
}

if (!IsStatic &&
ContainingType.IsInterface &&
IsSetOnEitherPart(Flags.RequiresBackingField) &&
// Should probably ignore initializer (and report ERR_InterfacesCantContainFields) if the
// property uses 'field' or has an auto-implemented accessor.
!IsSetOnEitherPart(Flags.HasInitializer))
{
diagnostics.Add(ErrorCode.ERR_InterfacesCantContainFields, Location);
}

if (!IsExpressionBodied)
{
bool hasGetAccessor = GetMethod is object;
Expand Down
Loading

0 comments on commit f1b2823

Please sign in to comment.