Improve MA0042 async overload matching coverage#1065
Conversation
Expand MA0042 overload matching to better handle generic inference, ref-kind compatibility, instance/extension lookup, and safe numeric conversions. Add a broad async-context test matrix covering generic compatibility, numeric conversion scenarios, and edge cases such as long->double and Half conversions. Also update DocumentationGenerator to use FindRequiredGitRepositoryRoot() and bump Meziantou.Framework.FullPath to 1.1.18. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace collection-expression returns with ImmutableArray.CreateRange/Empty in MA0042 overload lookup paths so builds succeed with older Roslyn toolsets used in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add MA0042 tests for same generic constraints (diagnostic) and different generic constraint order (no diagnostic), and keep coverage for different type-parameter mapping with the same generic definition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adjust MA0042 overload matching so List<T> to IEnumerable<T> generic overloads are not treated as equivalent async replacements. Update tests accordingly by asserting no diagnostic for this case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
|
||
| class Test | ||
| { | ||
| public void A(in int value) => throw null; |
There was a problem hiding this comment.
may be there should be separate analyzer without fix for in, ref and out, because modifiers are forbidden for async methods but you can rewrite it to async version
There was a problem hiding this comment.
The code should only accept the in modifier. out and ref would be incompatible. While it's an invalid modifier when you define an async method, an async method can use a method with a in parameter.
As the use-case is to replace method invocation, I think this is ok.
Task Foo(in int a) => throw null!;
async Task Bar(int a)
{
await Foo(a); // Valid
}There was a problem hiding this comment.
this sounds reasonable
But I'm talking about other case
bool TryA(int b, out Foo f) => throw null!;
Task(bool, Foo)> TryAAsync(int b) => throw null!;
I understand that it's a long shot for analyzer to guess this type of overload, but it can be usefull :)
There was a problem hiding this comment.
It would have more impact that just finding the overload. The code fix must be aware of it, not just using another method name, but assigning variables (it can be tricky depending on the context).
Replace namespace string comparisons in OverloadFinder with assembly metadata symbol resolution for IEnumerable<T> and Half detection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # src/DocumentationGenerator/Program.cs
Rename GenericArgument_NestedCompatibleGenericDefinitions_ShouldReport to GenericArgument_CompatibleGenericDefinitions_ShouldReport for clearer intent after merge. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add OverloadOptions switches to disable numeric conversions, params/non-params compatibility, in-modifier compatibility, and interface conversions. Wire these options through OverloadFinder matching and MA0042 call-site checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Flip newly added OverloadOptions toggles from Disable* to Allow* semantics with default true values, and update OverloadFinder checks accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Why
MA0042overload detection was missing several realistic call-shape scenarios (generic inference, extension-vs-instance matching, ref-kind nuances, and numeric conversion compatibility), which caused false negatives in async context diagnostics.What changed
OverloadFinderto better support:ref/outstrictness within/by-value compatibilitySystem.Half -> float/double)DoNotUseBlockingCallInAsyncContextAnalyzerby broadening lookup around receiver/type context.default,null, named args) and modifier edge casesDocumentationGeneratorto useFindRequiredGitRepositoryRoot()and bumpedMeziantou.Framework.FullPathto1.1.18.Validation
dotnet test --filter "FullyQualifiedName~DoNotUseBlockingCallInAsyncContextAnalyzer_AsyncContextTests.Argument_ImplicitNumeric"(passed)dotnet test --filter "FullyQualifiedName~DoNotUseBlockingCallInAsyncContextAnalyzer_AsyncContextTests"(passed)dotnet run --project src/DocumentationGeneratorcurrently fails in this worktree withCannot find the current git folderin this environment; code was updated toward required FullPath usage.