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

Fix ordering issue in analyzer callbacks for nested actions in symbol start analyzers #68490

Merged
merged 3 commits into from
Jul 17, 2023
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 @@ -214,12 +214,10 @@ public static void AnalyzeNamedTypeStart(
// Ensure that any analyzers for containing types are created and they hear about any reference to their
// fields in this nested type.

var hadContainingTypeAnalyzer = false;
for (var containingType = startSymbol.ContainingType; containingType != null; containingType = containingType.ContainingType)
{
var containgTypeAnalyzer = TryGetOrCreateAnalyzer(containingType);
RegisterFieldOrPropertyAnalysisIfNecessary(containgTypeAnalyzer);
hadContainingTypeAnalyzer = hadContainingTypeAnalyzer || containgTypeAnalyzer != null;
}

// Now try to make the analyzer for this type.
Expand All @@ -229,13 +227,6 @@ public static void AnalyzeNamedTypeStart(
RegisterFieldOrPropertyAnalysisIfNecessary(analyzer);
context.RegisterSymbolEndAction(analyzer.OnSymbolEnd);
}
else if (hadContainingTypeAnalyzer)
{
// We didn't create an analyze for this type. But we have containing types with analyzers. Ensure
// we register a symbol-end analyzer for us. The analysis subsystem needs this to ensure that outer
// analyzers don't complete until its nested types are done.
context.RegisterSymbolEndAction(static _ => { });
}

return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,9 @@ async Task onSymbolAndMembersProcessedAsync(ISymbol symbol, DiagnosticAnalyzer a
}

await processContainerOnMemberCompletedAsync(symbol.ContainingNamespace, symbol, analyzer).ConfigureAwait(false);
await processContainerOnMemberCompletedAsync(symbol.ContainingType, symbol, analyzer).ConfigureAwait(false);

for (var type = symbol.ContainingType; type != null; type = type.ContainingType)
await processContainerOnMemberCompletedAsync(type, symbol, analyzer).ConfigureAwait(false);
}

async Task processContainerOnMemberCompletedAsync(INamespaceOrTypeSymbol containerSymbol, ISymbol processedMemberSymbol, DiagnosticAnalyzer analyzer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ void processMembers(IEnumerable<ISymbol> members)
}
}

if (member.Kind != symbol.Kind &&
member is INamedTypeSymbol typeMember)
if (member is INamedTypeSymbol typeMember)
{
processMembers(typeMember.GetMembers());
}
Expand Down