Skip to content

Breaking change: use declaration-block safe-context for Span-valued collection expressions #9750

@RikkiGibson

Description

@RikkiGibson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Proposal QuestionQuestion to be discussed in LDM related to a proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions