/** * Check if ".Result" is accessed on a 'ValueTask' * - ignore the call if it's called inside an 'if (valueTask.IsCompletedSuccessfully)' */ public override void VisitMemberAccessExpression(MemberAccessExpressionSyntax node) { if (node.IsPropertyInvocation(ValueTaskTypes, "Result", semanticModel) && GetLeftMostIdentifier(node) is IdentifierNameSyntax identifierName && this.semanticModel.GetSymbolInfo(identifierName).Symbol is ISymbol symbol && !VerifiedForSuccessfulCompletion.Contains(symbol)) { AddToSymbolUsages(symbol, identifierName); ConsumedButNotCompleted.Add(identifierName); } base.VisitMemberAccessExpression(node); }
/** * Check if it's the wanted method on a ValueTask * - we treat AsTask() like await - always add it to the list * - for GetAwaiter().GetResult() - ignore the call if it's called inside an 'if (valueTask.IsCompletedSuccessfully)' */ public override void VisitInvocationExpression(InvocationExpressionSyntax node) { if (node.Expression is MemberAccessExpressionSyntax memberAccess) { if (node.IsMethodInvocation(ValueTaskTypes, "AsTask", semanticModel) && GetLeftMostIdentifier(memberAccess) is IdentifierNameSyntax identifier1) { AddToSymbolUsages(this.semanticModel.GetSymbolInfo(identifier1).Symbol, identifier1); } if (node.IsMethodInvocation(ValueTaskTypes, "GetResult", semanticModel) && GetLeftMostIdentifier(memberAccess) is IdentifierNameSyntax identifier2 && this.semanticModel.GetSymbolInfo(identifier2).Symbol is ISymbol symbol2 && !VerifiedForSuccessfulCompletion.Contains(symbol2)) { AddToSymbolUsages(symbol2, identifier2); ConsumedButNotCompleted.Add(identifier2); } } base.VisitInvocationExpression(node); }