Skip to content

Commit

Permalink
Fixed exception throw on sync completion of async lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Feb 17, 2024
1 parent 3d09840 commit 3ef82a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public AsyncResultExpression(bool valueTask)
/// </remarks>
public override Type Type => taskType;

// indicates that AsyncResult cannot throw exception so it can be inlined
internal bool IsSimpleResult
=> AsyncResult is ConstantExpression or ParameterExpression or DefaultExpression;

/// <summary>
/// Translates this expression into predefined set of expressions
/// using Lowering technique.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ private Expression VisitAsyncResult(AsyncResultExpression expr)
var prologue = context.CurrentStatement.PrologueCodeInserter();
expr = (AsyncResultExpression)base.VisitExtension(expr);

var containsAwait = ExpressionAttributes.Get(expr.AsyncResult) is { ContainsAwait: true };

if (containsAwait && Task.HasResult)
if (Task.HasResult && expr.IsSimpleResult is false)
{
ResultVariable ??= Expression.Parameter(Task.ResultType);
prologue(Expression.Assign(ResultVariable, expr.AsyncResult));
Expand Down

0 comments on commit 3ef82a9

Please sign in to comment.