Skip to content

Commit

Permalink
Merge pull request #10468 from workgroupengineering/fixes/core/tools/…
Browse files Browse the repository at this point in the history
…AvaloniaPropertyAnalyzer/AVP1031

fix(AvaloniaPropertyAnalyzer): Avoid AVP1031 when Avalonia Field Acce…
  • Loading branch information
grokys authored Mar 1, 2023
2 parents 1809ac2 + e99e4ef commit 24ad4af
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ invocation.Arguments[inheritsParam.Ordinal].Value is ILiteralOperation literalOp
hostTypeRef = new(_avaloniaObjectType, Location.None); // assume that an attached property applies everywhere until we find its registration
}
var result = new AvaloniaPropertyDescription(inferredName, propertyType, valueType) { HostType = hostTypeRef };
var result = new AvaloniaPropertyDescription(inferredName, propertyType, valueType) { HostType = hostTypeRef };
// assume that the property is owned by its containing type at the point of assignment, until we find its registration
result.SetAssignment(s, new(s.ContainingType, Location.None));
Expand Down Expand Up @@ -570,7 +570,7 @@ private void AnalyzeMethodInvocation(OperationAnalysisContext context)

if (_allGetSetMethods.Contains(originalMethod))
{
if (invocation.Instance is IInstanceReferenceOperation { ReferenceKind: InstanceReferenceKind.ContainingTypeInstance } &&
if (invocation.Instance is IInstanceReferenceOperation { ReferenceKind: InstanceReferenceKind.ContainingTypeInstance } &&
GetReferencedProperty(invocation.Arguments[0]) is { } refProp &&
refProp.description.AssignedTo.TryGetValue(refProp.storageSymbol, out var ownerType) &&
!DerivesFrom(context.ContainingSymbol.ContainingType, ownerType.Type) &&
Expand Down Expand Up @@ -694,9 +694,14 @@ private void AnalyzeWrapperCrlProperty(SymbolAnalysisContext context)

void VerifyAccessor(IMethodSymbol? method, string verb, string methodName)
{
if (method == null)
if (method is null)
{
context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName));
if (avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Public ||
(avaloniaPropertyStorage.DeclaredAccessibility == Accessibility.Protected
&& avaloniaPropertyStorage.ContainingSymbol.DeclaredAccessibility == Accessibility.Public))
{
context.ReportDiagnostic(Diagnostic.Create(MissingAccessor, property.Locations[0], avaloniaPropertyStorage, verb, methodName));
}
}
else if (method.DeclaredAccessibility != avaloniaPropertyStorage.DeclaredAccessibility && method.DeclaredAccessibility != property.DeclaredAccessibility)
{
Expand Down

0 comments on commit 24ad4af

Please sign in to comment.