dotnet/roslyn#80107
The implementation is out of accordance with the spec, and is giving collection-exprs a "function member" safe-context instead of "declaration block". Changing implementation to align with the spec would be a breaking change, so, we need to decide whether to fix impl or change the spec somehow to align with the implementation.
scoped Span<int> items1 = default;
scoped Span<int> items2 = default;
foreach (var x in new[] { 1, 2 })
{
Span<int> items = [x];
if (x == 1)
items1 = items;
if (x == 2)
items2 = items;
}
Console.Write(items1[0]); // '2'
Console.Write(items2[0]); // '2'
Resolution: Take the breaking change to make implementation align with specification. However, take care to build our partner repos with the modified compiler, and investigate any new build errors before shipping the change, to make sure the severity of the break is manageable.