Skip to content

Slicing a static array binds as non-ref when using auto ref #5434

Open
@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

Steven Schveighoffer reported this on 2024-02-10T16:49:35Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24385

Description

```d
import std.stdio;
void foo(ref int[2] val)
{
    writeln("foo ref");
}

void foo(int[2] val)
{
    writeln("foo non-ref");
}

void bar()(auto ref int[2] val)
{
    static if(__traits(isRef, val))
        writeln("bar ref");
    else
        writeln("bar non-ref");
}

void main()
{
    int[4] x;
    int[2] y;
    foo(y);         // foo ref
    bar(y);         // bar ref
    foo(x[0 .. 2]); // foo ref
    bar(x[0 .. 2]); // bar non-ref
}
```

They should all be ref for consistency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions