Fix the MA0166 message saying "available tokens" - #1513
Merged
Merged
Conversation
MA0166 reports the TimeProvider expressions available in the scope, but its message called them "tokens", which was copied from UseAnOverloadThatHasCancellationTokenAnalyzer along with the rest of the file. It read as "Use an overload with a TimeProvider, available tokens: timeProvider", which is confusing next to MA0032/MA0040, where the same wording really is about CancellationToken. Rename the identifiers that came from the same copy-paste and were still talking about cancellation tokens, and explain the SpecialType range used to skip the types that cannot contain a TimeProvider. No test asserted on the message, so add one to pin the wording.
This was referenced Sep 12, 2026
Closed
This was referenced Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
MA0166(Forward the TimeProvider to methods that take one) formats the list ofTimeProviderexpressions available in the scope into its message, but called them tokens:The file was derived from
UseAnOverloadThatHasCancellationTokenAnalyzerand the wording was never updated. It is confusing next toMA0032/MA0040, where the same wording really is aboutCancellationToken.The message is now:
Also in this change
The same copy-paste left several identifiers talking about cancellation tokens; they are renamed to match what they actually hold:
availableCancellationTokens→availableTimeProvidersCreateProperties(string[] cancellationTokens, …)→timeProvidersIsArgumentImplicitlyDeclared(…, INamedTypeSymbol cancellationTokenSymbol, …)→timeProviderSymbol(the argument passed at the call site is alreadyTimeProviderSymbol)The comment above the
(int)symbol.SpecialType is >= 1 and <= 45fast path is expanded to say what the range means. Checking the Roslyn packages confirms the enum grew past 45 (System_Runtime_CompilerServices_InlineArrayAttributeandSystem_Runtime_CompilerServices_AsyncHelpersexist in 5.9 but not in 4.8), so the bound covers every special type of the oldest supported Roslyn version and the newer ones are simply not skipped — a missed fast path, not a correctness issue. The bound itself is left unchanged, as widening it is a behaviour change beyond this fix.No behaviour other than the message text changes: the diagnostic properties consumed by the code fix (
ParameterIndexKey,ParameterNameKey,PathsKey) are untouched.Tests
No test asserted on the MA0166 message, so
ReportsTheAvailableTimeProvidersInTheMessageis added to pin the wording, mirroring the equivalent MA0040 test.UseAnOverloadThatHasTimeProviderAnalyzerTests: 18/18 passing on roslyn4.8, 4.14, 5.0, 5.6 and 5.9dotnet run --project src/DocumentationGenerator: exit code 0, no markdown change (the docs surface rule titles, not message formats)