Skip to content

[Version 11.0] Feature support for required members - #1597

Draft
RexJaeschke wants to merge 16 commits into
draft-v11from
v11-required-members
Draft

RexJaeschke wants to merge 16 commits into
draft-v11from
v11-required-members

Conversation

@RexJaeschke

Copy link
Copy Markdown
Contributor

This is Rex's adaptation of the corresponding MS proposal.

Open Issue: Combining required with ref or ref readonly

The MS spec states that,

required cannot be combined with the following modifiers: …, ref, ref readonly, …

I have confirmed that while this is true for properties, it is not true for fields. The following compiles:

public ref struct S2
{
    [SetsRequiredMembers]
    public S2() { }
    public static int x = 555;
 
    public          ref int r1a = ref x;
    public required ref int r1b = ref x;
    public          ref readonly int r2a = ref x;
    public required ref readonly int r2b = ref x;
}

    var s2 = new S2();
    Console.WriteLine($"S2.x   = {S2.x}");
    Console.WriteLine($"s2.r1a = {s2.r1a}");
    Console.WriteLine($"s2.r1b = {s2.r1b}");
    Console.WriteLine($"s2.r2a = {s2.r2a}");
    Console.WriteLine($"s2.r2b = {s2.r2b}");

Is the MS spec wrong/out-of-date, or am I missing something?

Bill Wagner stated: I don’t see any notes in LDM meetings. But, I think the spec was a bit vague, and was originally meant to focus on properties. I’m hoping Fred can shed more light on it.

Fred Silberberg stated: Required members supports both fields and properties, but I'm not sure whether we specifically considered the intersection given the late-breaking nature of the way ref fields were developed. Likely we should block this.

@RexJaeschke RexJaeschke added this to the C# 11 milestone Mar 7, 2026
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Mar 7, 2026
@RexJaeschke
RexJaeschke marked this pull request as draft March 7, 2026 16:13
@BillWagner
BillWagner force-pushed the v11-required-members branch from cc1f70b to 2ede9c1 Compare April 29, 2026 19:41
@BillWagner
BillWagner force-pushed the v11-required-members branch from 3c6b27a to 73c9ad0 Compare May 13, 2026 16:36
@BillWagner
BillWagner force-pushed the v11-required-members branch from 73c9ad0 to 42ef70d Compare June 24, 2026 20:16
@BillWagner

Copy link
Copy Markdown
Member

An earlier version of this feature is already present on v11-alpha from a prior meeting. Edits made to this PR since then are not yet on v11-alpha; they will land at the next propagation. If you need them on v11-alpha sooner, please open a separate PR targeting v11-alpha.
Thanks!

@BillWagner
BillWagner force-pushed the v11-required-members branch from 42ef70d to cdcf0a8 Compare July 24, 2026 19:57
@BillWagner
BillWagner force-pushed the v11-required-members branch 4 times, most recently from 939b378 to 651e972 Compare September 21, 2026 19:20
@BillWagner
BillWagner force-pushed the v11-required-members branch from 651e972 to e3c9067 Compare October 14, 2026 18:11
BillWagner added a commit that referenced this pull request Oct 14, 2026
[Version 11.0] Feature support for required members
Authoritative source v11-required-members 651e972; reviewed-source replay e3c9067.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
RexJaeschke and others added 15 commits November 12, 2026 15:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Add that this applies to structs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
BillWagner added a commit that referenced this pull request Nov 12, 2026
Preserve current committee source and genuine feature additions; resolve the recorded mechanical source overlap.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 361b9a77-2b4c-45e6-969f-e6785c47f27e
Add additional requirements that were missing in the required members PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants