Skip to content

Alias to member of field doesn't work inside method #22232

@ntrel

Description

@ntrel

Support for an alias aggregate type member resolving to a member of a field was added in #20610. However, that only seems to work outside the aggregate type. In particular:

struct Foo
{
    int v;
}

struct Bar
{
    Foo f;
    alias v = f.v;

    void test()
    {
        assert(v == 3); // error, requires an instance of Foo
        alias w = f.v;
        w++; // error, requires an instance of Foo
    }
}

Walter then mentioned ambiguities and trouble: #20610 (comment)

Unless all cases like #17532 are to be supported, I'm thinking fixing #20610 just confuses things.

Edition error

Another problem is that before #20610 was fixed, I made a PR for the next edition to detect aliases like v and w and error: #15863. If the #20610 fix should stay, the edition error needs tweaking (one of the cases is still needed). I looked at allowing #20610 but for some reason an alias declaration in a function is getting a null from toParent, not a FuncDeclaration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions