Skip to content

Fix ElseIfStatement double-evaluation in awaited context#485

Merged
sebastienros merged 1 commit intosebastienros:mainfrom
lahma:fix-double-write-elsif
Apr 1, 2022
Merged

Fix ElseIfStatement double-evaluation in awaited context#485
sebastienros merged 1 commit intosebastienros:mainfrom
lahma:fix-double-write-elsif

Conversation

@lahma
Copy link
Copy Markdown
Collaborator

@lahma lahma commented Apr 1, 2022

This code in awaited context check caused elseIf.WriteToAsync to always start writing, even when it should be only started if condition is true:

if (!elseIfConditionTask.IsCompletedSuccessfully)
{
    var writeTask = elseIf.WriteToAsync(writer, encoder, context);
    return AwaitedElseBranch(elseIfConditionTask, writeTask, writer, encoder, context, i + 1);

Parametrized test case to test async and non-async paths the get some red tests and then fixed. Now passing the elseIf and write task is retrieved, if needed.

We found out this when running on Linux against sync code, which was quite curious, on Windows it always worked.

@sebastienros sebastienros merged commit f2f99f9 into sebastienros:main Apr 1, 2022
@lahma lahma deleted the fix-double-write-elsif branch April 1, 2022 19:29
@lahma
Copy link
Copy Markdown
Collaborator Author

lahma commented Apr 1, 2022

@sebastienros this bug was somewhat nasty and unpredictable (template writing both elsif and else content), should there be a new release?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants