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).
Comment #1 by robert.schadek — 2024-12-13T19:32:42Z