Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a ref field to refer to a ref struct type #62243

Closed
cston opened this issue Jun 29, 2022 · 3 comments
Closed

Allow a ref field to refer to a ref struct type #62243

cston opened this issue Jun 29, 2022 · 3 comments

Comments

@cston
Copy link
Member

cston commented Jun 29, 2022

Currently, ref fields cannot refer to ref struct types.

ref struct R1<T>
{
}

ref struct R2<T>
{
    public ref R1<T> F; // error CS9050: A ref field cannot refer to a ref struct.
}

See #62186

See also #62098

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 29, 2022
@jcouv jcouv added this to the Compiler.Next milestone Jun 29, 2022
@jcouv jcouv added Feature Request and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 29, 2022
@SK-Genius
Copy link

And Allow it recursive:

ref struct ParentIds
{
    int Id;
    readonly ref ParentIds Parent;
} 

without

error CS9050: A ref field cannot refer to a ref struct

and

error CS0523: Struct member 'ParentIds.Parent' of type 'ParentIds' cause a cycle in the struct layout

@SK-Genius
Copy link

Maybe also introduce something like

ref struct ReadOnlyRefStack<T>
{
    T Item;
    readonly ref readonly ReadOnlyRefStack<T> Prev;

    //[...]
}

and

static string Join(ReadOnlySpan<char> seperator, params ReadOnlyRefStack<string> values) => // ...

@jaredpar
Copy link
Member

Closing as this is less a compiler issue and more a language design issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants