Thread overview
[Issue 20821] Aliased template method confuses overload resolution
May 11, 2020
Max Samukha
May 11, 2020
Basile-z
May 11, 2020
Basile-z
May 12, 2020
Basile-z
May 12, 2020
Basile-z
Dec 21, 2020
Dlang Bot
Dec 21, 2020
Dlang Bot
May 11, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

Max Samukha <maxsamukha@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxsamukha@gmail.com
           Hardware|x86                         |All
                 OS|Windows                     |All

--
May 11, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

--- Comment #1 from Basile-z <b2.temp@gmx.com> ---
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.

--
May 11, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |b2.temp@gmx.com

--- Comment #2 from Basile-z <b2.temp@gmx.com> ---
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.

--
May 12, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

--- Comment #3 from Basile-z <b2.temp@gmx.com> ---
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.

--
May 12, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

--- Comment #4 from Basile-z <b2.temp@gmx.com> ---
The alias is more like

  template fun()
  {
    alias fun = gun;
  }

to make the shortand syntax work this is how things must be lowered.

--
December 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
December 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20821

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--