Skip to content

Commit 7ba700e

Browse files
committed
Fix some analyzer bugs
1 parent c6ca94d commit 7ba700e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/WinRTGeneratedBindableCustomPropertyWithBasesMemberAnalyzer.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void Initialize(AnalysisContext context)
6161
}
6262

6363
// Warn on all [ObservableProperty] fields
64-
foreach (IFieldSymbol fieldSymbol in FindObservablePropertyFields(typeSymbol, relayCommandSymbol))
64+
foreach (IFieldSymbol fieldSymbol in FindObservablePropertyFields(typeSymbol, observablePropertySymbol))
6565
{
6666
context.ReportDiagnostic(Diagnostic.Create(
6767
WinRTGeneratedBindableCustomPropertyWithBaseObservablePropertyOnField,
@@ -94,7 +94,7 @@ private static IEnumerable<IMethodSymbol> FindRelayCommandMethods(INamedTypeSymb
9494
{
9595
// Check whether the base type (if any) is from the same assembly, and stop if it isn't. We do not
9696
// want to include methods from the same type, as those will already be caught by another analyzer.
97-
if (!SymbolEqualityComparer.Default.Equals(typeSymbol.ContainingAssembly, typeSymbol.BaseType))
97+
if (!SymbolEqualityComparer.Default.Equals(typeSymbol.ContainingAssembly, typeSymbol.BaseType?.ContainingAssembly))
9898
{
9999
yield break;
100100
}
@@ -117,7 +117,13 @@ private static IEnumerable<IMethodSymbol> FindRelayCommandMethods(INamedTypeSymb
117117
/// <returns>All <see cref="IFieldSymbol"/> instances for matching members.</returns>
118118
private static IEnumerable<IFieldSymbol> FindObservablePropertyFields(INamedTypeSymbol typeSymbol, INamedTypeSymbol observablePropertySymbol)
119119
{
120-
foreach (ISymbol memberSymbol in typeSymbol.GetAllMembersFromSameAssembly())
120+
// Skip the base type if not from the same assembly, same as above
121+
if (!SymbolEqualityComparer.Default.Equals(typeSymbol.ContainingAssembly, typeSymbol.BaseType?.ContainingAssembly))
122+
{
123+
yield break;
124+
}
125+
126+
foreach (ISymbol memberSymbol in typeSymbol.BaseType.GetAllMembersFromSameAssembly())
121127
{
122128
if (memberSymbol is IFieldSymbol fieldSymbol &&
123129
fieldSymbol.HasAttributeWithType(observablePropertySymbol))

0 commit comments

Comments
 (0)