Issue 24350 - Cannot access a member of an 'alias this' member through an alias
Summary: Cannot access a member of an 'alias this' member through an alias
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-21 08:12 UTC by Max Samukha
Modified: 2024-01-21 08:12 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2024-01-21 08:12:46 UTC
Some people don't consider this a bug, but I do, hence the report.

struct S 
{
    int x;
}

struct S2
{
    S s;
    alias this = s;
    alias x = S.x;
}

auto x = S2().x; // fail

One of the practical consequences of this, which effected my work, is the impossibility to overload functions in a way consistent with other cases of name importing. Compare:

1)
class A
{
    void foo() {}
}

class B: A
{
    alias foo = A.foo;
    void foo(int) {}
}

void main()
{
    (new B).foo(); // pass
}

2)
template A()
{
    void foo() {}
}

struct B
{
   mixin A a;
   alias foo = a.foo;
   void foo(int) {}
}

void main()
{
    B().foo(); // pass
}

3)
struct A
{
    void foo() {}
}

struct B
{
    A a;
    alias this = a;
    alias foo = A.foo;
    void foo(int) {}
}

void main()
{
    B().foo(); // fail
}

While some people put 1) and 3) in different categories, I don't see a good reason for that - B in 3) is implicitly convertible to A, similar to 1).