Extensions: consider adjusting receiver requirements for extension members
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
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.
```c#
[Fact]
public void ExtensionMemberLookup_ObjectInitializer_Conversion_02()
{
var src = """
_ = new System.ReadOnlySpan() { Property = 42 };
new System.ReadOnlySpan().Property = 43;
class C { }
static class E
{
extension(System.ReadOnlySpan 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() { 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().Property = 43;
Diagnostic(ErrorCode.ERR_AssgLvalueExpected, "new System.ReadOnlySpan().Property").WithLocation(3, 1));
}
```
Relates to test plan https://github.com/dotnet/roslyn/issues/76130
Contributor guide
Assessment
This issue has not been assessed yet.