roslyn: bug either in Roslyn or in the C# language spec — example with `ReadOnlySpan` in a `foreach` expansion
This is an issue I originally reported in the C# lang. spec repo. My original report was for the C# specification, as my assumption was that the specified foreach
expansion was inaccurate. Consider the program below, which is compiled without errors.
public class C
{
public async Task M()
{
IReadOnlyList<string> o = null;
foreach (ReadOnlySpan<char> c in o) {}
return;
}
}
Expanding its foreach
as according to the specification introduces a diagnostic:
error CS4012: Parameters or locals of type ‘ReadOnlySpan<char>’ cannot be declared in async methods or async lambda expressions.
But it turns out that, according to @CyrusNajmabadi and @333fred , the real issue is that my original program is ilegal, even accepted by Roslyn. So I was told to open an issue here.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (9 by maintainers)
Commits related to this issue
- comment out code due to https://github.com/dotnet/roslyn/issues/62747 — committed to ShiftLeftSecurity/jellyfin by ltcmelo 2 years ago
- Disallow more locals of restricted type in async methods (#66264) Fixes https://github.com/dotnet/roslyn/issues/62747 — committed to dotnet/roslyn by jcouv a year ago
@CyrusNajmabadi , how I’m (or anyone else is) expanding it is circumstantial—the expansion is governed by the language specification. But here it is, as you ask:
Note: The
_L10C8
suffix is just a convention to indicate that the (original) expression occurs at Line 10 and Column 8.