Bug 20821 – Aliased template method confuses overload resolution

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-11T13:12:24Z
Last change time
2020-12-21T07:13:02Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2020-05-11T13:12:24Z
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.
Comment #2 by b2.temp — 2020-05-11T21:28:26Z
overload insertion in the problematic example happens here: https://github.com/dlang/dmd/blob/b81f10c4b62bb55813f031ee18ef7f4d08cfcb80/src/dmd/declaration.d#L784-L791 something is missing when the symbol is a OverDeclaration created at this place. When replaced with an OverloadSet the TC works but a couple of things break in the test suite.
Comment #3 by b2.temp — 2020-05-12T05:10:46Z
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.
Comment #5 by dlang-bot — 2020-12-21T06:34:16Z
@BorisCarvajal created dlang/dmd pull request #12042 "Fix Issue 20821 - Aliased template method confuses overload resolution" fixing this issue: - Fix Issue 20821 - Aliased template method confuses overload resolution https://github.com/dlang/dmd/pull/12042
Comment #6 by dlang-bot — 2020-12-21T07:13:02Z
dlang/dmd pull request #12042 "Fix Issue 20821 - Aliased template method confuses overload resolution" was merged into master: - 2a69e41e942cc5f0147f750d11992b71576ee7b0 by Boris Carvajal: Fix Issue 20821 - Aliased template method confuses overload resolution https://github.com/dlang/dmd/pull/12042