Comment #0 by qs.il.paperinik — 2021-01-20T18:53:30Z
If a mixin template only mixes in one name and that name is shadowed, this should be an error. It is almost always unintended.
For mixin templates that declares multiple names, partial shadowing could be the intended behavior, and as a corner case, full shadowing, too. Meta-programming code would be complicated unnecessarily if it had to check that not all members of a mixin template are shadowed. However, if the mixin template contains one member (one name) only, shadowing is very likely to be unintended.
Unless the mixin template name is a template parameter, the author of the mixin statement has control over it.
Example code:
mixin template M()
{
void f() { }
}
struct S
{
int f(int x) { return x; }
mixin M; // does nothing
}
void main()
{
S s;
s.f(); // error
}
The improvement would be:
mixin template M()
{
void f() { }
}
struct S
{
int f(int x) { return x; }
mixin M; // error: only member `M().f` of `M()` shadowed.
}
The corrective action would be to give the mixin a name and alias the eponymous member(s):
mixin template M()
{
void f() { }
}
struct S
{
int f(int x) { return x; }
mixin M m;
alias f = m.f;
}
Comment #1 by robert.schadek — 2024-12-13T19:14:09Z