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

Suppress reporting VSTHRD114 diagnostic on Task? returning methods #866

Merged
merged 1 commit into from Jun 22, 2021

Conversation

bluetarpmedia
Copy link
Contributor

@bluetarpmedia bluetarpmedia commented Jun 15, 2021

VSTHRD114 now ignores C# methods returning Task?

Converted VSTHRD114 to an abstract base class in order to use LanguageUtils.

This implementation uses syntax nodes to detect the nullable return type, which means the Roslyn CodeAnalysis does not need to be upgraded.

It prevents VSTHRD114 warnings on cases like these:

public Task? GetTask()
{
    return null;
}

public Task<int>? GetTaskOfInt()
{
    return null;
}

public Task<object?>? GetTaskOfNullableObject()
{
    return null;
}

public void LocalFunc()
{
    Task<object>? GetTaskObj()
    {
        return null;
    }
}

But it doesn't prevent warnings for anonymous functions or lambdas, like:

public void StillProducesWarning()
{
    Func<Task?> func = () =>
    {
        return null;
    };
}

If and when the Roslyn upgrade happens the implementation can be simplified to use IMethodSymbol.ReturnNullableAnnotation and that will solve the anon/lambda cases too.

Closes #637

…ble tasks. The implementation uses syntax nodes to detect the nullable return type. Converted VSTHRD114 to an abstract base class in order to use LanguageUtils.
@AArnott AArnott changed the title Fix for #637 Suppress reporting VSTHRD114 diagnostic on Task? returning methods Jun 22, 2021
Copy link
Member

@AArnott AArnott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well done. Thank you!

@AArnott AArnott added this to the v17.0 milestone Jun 22, 2021
@AArnott AArnott merged commit 46bc753 into microsoft:main Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VSTHRD114: fires even in the function is annotated as returning nullable Tasks
2 participants