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

CA1859 does not apply to async methods returning a Task<T> #7262

Open
martincostello opened this issue Mar 23, 2024 · 0 comments
Open

CA1859 does not apply to async methods returning a Task<T> #7262

martincostello opened this issue Mar 23, 2024 · 0 comments

Comments

@martincostello
Copy link
Member

martincostello commented Mar 23, 2024

Analyzer

Diagnostic ID: CA1859

Describe the improvement

The following method raises CA1859, suggesting that the return type is changed to List<string>:

private static IList<string> GetList()
{
    return new List<string>();
}

The same pattern is however not detected for async methods returning a Task<T>. The following code does not suggest that Task<IList<string>> is changed to Task<List<string>>:

private static async Task<IList<string>> GetListAsync()
{
    await Task.CompletedTask;
    return new List<string>();
}

The above examples are trivialised versions of a real async method where I noticed returning an IList<T> wasn't suggesting the use of a List<T>.

Describe suggestions on how to achieve the rule

Change the rule to consider the real type that is used to create the Task<T>.

Additional context

None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant