[Issue 24717] alias edge cases with tupleof

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 28 11:24:11 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24717

Nick Treleaven <nick at geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick at geany.org
            Summary|alias edge cases            |alias edge cases with
                   |                            |tupleof

--- Comment #2 from Nick Treleaven <nick at geany.org> ---
> alias y = s.tupleof[0]; // this is a compile error?!

Inside a function, `.tupleof` on a struct/static array instance should be
implemented as a symbol sequence of implicit ref declarations:

struct S
{
    int i;
    char c;
}

void main()
{
    S s = {2, 'c'};
    ref __si = s.i;
    ref __sc = s.c;
    alias tupleof = AliasSeq!(__si, __sc); // should be the same as s.tupleof

    alias a = tupleof[0]; // works
    a++;
    assert(s.i == 3);

    alias z = AliasSeq!tupleof; // works
    assert(++z[0] == 4);
}

> alias z = AliasSeq!(s.tupleof); // error, but it should be a no-op

That line doesn't error, but using z does:

    z[0].writeln(); // Error: accessing non-static variable `x` requires an
instance of `S`

--


More information about the Digitalmars-d-bugs mailing list