Skip to content

Extensions: consider adjusting receiver requirements for extension members #79451

@jcouv

Description

@jcouv

This issue is referenced in source.
The following scenario illustrates a diagnostic produced by check in CheckPropertyValueKind which may not be applicable for extension properties.

    [Fact]
    public void ExtensionMemberLookup_ObjectInitializer_Conversion_02()
    {
        var src = """
_ = new System.ReadOnlySpan<string>() { Property = 42 };

new System.ReadOnlySpan<string>().Property = 43;

class C { }

static class E
{
    extension(System.ReadOnlySpan<object> s)
    {
        public int Property { set { } }
    }
}
""";

        // Tracked by https://github.com/dotnet/roslyn/issues/76130 : consider adjusting receiver requirements for extension members
        var comp = CreateCompilation(src, targetFramework: TargetFramework.Net90);
        comp.VerifyEmitDiagnostics(
            // (1,41): error CS0131: The left-hand side of an assignment must be a variable, property or indexer
            // _ = new System.ReadOnlySpan<string>() { Property = 42 };
            Diagnostic(ErrorCode.ERR_AssgLvalueExpected, "Property").WithLocation(1, 41),
            // (3,1): error CS0131: The left-hand side of an assignment must be a variable, property or indexer
            // new System.ReadOnlySpan<string>().Property = 43;
            Diagnostic(ErrorCode.ERR_AssgLvalueExpected, "new System.ReadOnlySpan<string>().Property").WithLocation(3, 1));
    }

Relates to test plan #76130

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions