[Zomp.SyncMethodGenerator.CreateSyncVersion] generates invalid sync code for an async iterator method that uses ReadOnlyMemory<T> and yield return.
The generated method rewrites a ReadOnlyMemory<T> local into ReadOnlySpan<T> inside an iterator and emits assignments that don’t type-check.
Minimal repro
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
public static partial class Repo
{
[Zomp.SyncMethodGenerator.CreateSyncVersion]
public static async IAsyncEnumerable<int> Foo(IAsyncEnumerable<ReadOnlyMemory<bool>> input, [EnumeratorCancellation] CancellationToken ct = default)
{
ReadOnlyMemory<bool> prev = default;
var hasPrev = false;
await foreach (var col in input.WithCancellation(ct))
{
if (hasPrev)
{
Helper(prev, col);
}
prev = col;
hasPrev = true;
yield return 1;
}
}
private static void Helper(ReadOnlyMemory<bool> a, ReadOnlyMemory<bool> b) { }
}
[Zomp.SyncMethodGenerator.CreateSyncVersion]generates invalid sync code for an async iterator method that usesReadOnlyMemory<T>andyield return.The generated method rewrites a
ReadOnlyMemory<T>local intoReadOnlySpan<T>inside an iterator and emits assignments that don’t type-check.Minimal repro