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

VSTHRD200 should consider derived type of awaitable type as awaitable #1023

Open
r-ramesh opened this issue Apr 14, 2022 · 0 comments
Open

Comments

@r-ramesh
Copy link

r-ramesh commented Apr 14, 2022

Derived types of awaitable types are not considered awaitable:

IMethodSymbol? getAwaiterMethod = typeSymbol.GetMembers(nameof(Task.GetAwaiter)).OfType<IMethodSymbol>().FirstOrDefault(m => m.Parameters.IsEmpty);
if (getAwaiterMethod is object)
{
isAwaitable = ConformsToAwaiterPattern(getAwaiterMethod.ReturnType);
}
else
{
IEnumerable<ITypeSymbol>? awaitableTypesFromThisAssembly = from candidateAwaiterMethod in compilation.GetSymbolsWithName(m => m == GetAwaiterMethodName, SymbolFilter.Member, cancellationToken).OfType<IMethodSymbol>()
where candidateAwaiterMethod.IsExtensionMethod && !candidateAwaiterMethod.Parameters.IsEmpty
where ConformsToAwaiterPattern(candidateAwaiterMethod.ReturnType)
select candidateAwaiterMethod.Parameters[0].Type;
IEnumerable<ITypeSymbol>? awaitableTypesPerAssembly = from assembly in compilation.Assembly.Modules.First().ReferencedAssemblySymbols
from awaitableType in GetAwaitableTypes(assembly)
select awaitableType;
isAwaitable = awaitableTypesFromThisAssembly.Concat(awaitableTypesPerAssembly).Contains(typeSymbol);

This results in false alarm of VSTHRD200 if the method name ends in Async but returns a derived type of awaitable type.

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

No branches or pull requests

2 participants