struct S {
int gun()(int i) { return 0; }
alias fun = gun;
int fun() { return 1; }
}
static assert(S().fun == 1); // Error
The above code gives the error message 'void has no value'. It seems it believes I'm referring to gun, while I'm in fact trying to call fun().
If an alias is not used, and gun is called fun instead, the above code works correctly.
Comment #1 by b2.temp — 2020-05-11T18:12:07Z
Another way to makes this works
static assert(S().fun() == 1); // explicit call with "()"
It looks like the overload set is not build corectly.
This is confirmed by
struct S {
int gun()(int i) { return 0; }
alias fun = gun;
int fun() { return 1; }
}
static assert(S().fun() == 1); // Error
static assert(__traits(getOverloads, S, "fun", true).length == 2);
while if the non templatized fun is declared before gun then the overload set has well its length equal to 2.
maybe this report is invalid after all, try
---
struct S {
int gun()(int i) { return 0; }
alias fun() = gun; // note the parens...
int fun() { return 1; }
}
static assert(S().fun == 1); // OK
static assert(S().fun!()(0) == 0); // OK
static assert(__traits(getOverloads, S, "fun", true).length == 2); // OK
---
Maybe that the alias template parameters could be implictly created when the alias RHS is not specialized.
Comment #4 by b2.temp — 2020-05-12T05:28:08Z
The alias is more like
template fun()
{
alias fun = gun;
}
to make the shortand syntax work this is how things must be lowered.