From 9501d2fd078349b7a9ada901e3b88edd717805d5 Mon Sep 17 00:00:00 2001 From: AnaCoda Date: Wed, 9 Aug 2023 11:31:02 -0600 Subject: [PATCH] (re)store previous m_removeAsyncAnywhere state --- .../Async/Generator/AsyncToSyncMethodTransformer.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs b/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs index 85adb723..2238429a 100644 --- a/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs +++ b/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs @@ -352,6 +352,8 @@ private StatementSyntax Transform( ExpressionStatementSyntax exprStmt ) { private ExpressionSyntax Transform( InvocationExpressionSyntax invocationExpr) { ITypeSymbol? returnTypeInfo = Model.GetTypeInfo( invocationExpr ).Type; + + bool prevRemoveAsyncAnywhereState = m_removeAsyncAnywhere; if( returnTypeInfo?.MetadataName == "IAsyncEnumerable`1" && returnTypeInfo.ContainingNamespace.ToString() == "System.Collections.Generic" ) { m_removeAsyncAnywhere = true; } @@ -369,9 +371,13 @@ private ExpressionSyntax Transform( InvocationExpressionSyntax invocationExpr) { return SyntaxFactory.ParseExpression( $"Task.Run(() => {invocationExpr}).Result" ); } - return invocationExpr + invocationExpr = invocationExpr .WithExpression( Transform( invocationExpr.Expression ) ) .WithArgumentList( TransformAll( invocationExpr.ArgumentList, Transform ) ); + + m_removeAsyncAnywhere = prevRemoveAsyncAnywhereState; + + return invocationExpr; } bool ShouldRemoveReturnedMemberAccess( MemberAccessExpressionSyntax memberAccessExpr ) {