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

Fix deconstruct and fully qualified types in async foreach #68

Merged
merged 2 commits into from
Mar 23, 2024

Conversation

GerardSmit
Copy link
Contributor

This PR fixes 2 bugs with await foreach that I encountered:

Deconstruct

Source

[CreateSyncVersion]
async Task<int> SumAsync(IAsyncEnumerable<(int a, int b)> enumerable)
{
    int sum = 0;

    await foreach (var (a, b) in enumerable)
    {
        sum += a + b;
    }

    return sum;
}

Before

await wasn't being removed from the foreach:

int Sum(global::System.Collections.Generic.IEnumerable<(int a, int b)> enumerable)
{
    int sum = 0;

    await foreach (var (a, b) in enumerable)
    {
        sum += a + b;
    }

    return sum;
}

After

int Sum(global::System.Collections.Generic.IEnumerable<(int a, int b)> enumerable)
{
    int sum = 0;

    foreach (var (a, b) in enumerable)
    {
        sum += a + b;
    }

    return sum;
}

Fully quallified type

Source

[CreateSyncVersion]
async Task<int> SumAsync(IAsyncEnumerable<int?> enumerable)
{
    int sum = 0;

    await foreach (int? i in enumerable)
    {
        if (i.HasValue)
        {
            sum += i.Value;
        }
    }
    
    return sum;
}

Before

await wasn't being removed from the foreach:

int Sum(global::System.Collections.Generic.IEnumerable<int?> enumerable)
{
    int sum = 0;

    await foreach (int? i in enumerable)
    {
        if (i.HasValue)
        {
            sum += i.Value;
        }
    }
    
    return sum;
}

After

int Sum(global::System.Collections.Generic.IEnumerable<int?> enumerable)
{
    int sum = 0;

    foreach (int? i in enumerable)
    {
        if (i.HasValue)
        {
            sum += i.Value;
        }
    }

    return sum;
}

@GerardSmit
Copy link
Contributor Author

I had a fight with the new line endings check, so I moved the tests to an already existing file.. 😅

@virzak virzak merged commit a3d7afb into zompinc:master Mar 23, 2024
3 checks passed
@virzak
Copy link
Contributor

virzak commented Mar 23, 2024

Thanks so much for the PR, @GerardSmit .

Version 1.3.38 has the changes.

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