Thread overview
[Issue 5363] const + alias this = wrong code
Jul 22, 2014
Marc Schütz
Sep 18, 2018
RazvanN
Oct 06, 2018
Walter Bright
Oct 06, 2018
Walter Bright
Oct 08, 2018
RazvanN
Oct 09, 2018
calex
Oct 19, 2018
Walter Bright
Dec 17, 2022
Iain Buclaw
July 22, 2014
https://issues.dlang.org/show_bug.cgi?id=5363

Marc Schütz <schuetzm@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schuetzm@gmx.net

--- Comment #6 from Marc Schütz <schuetzm@gmx.net> ---
Just tested with latest DMD git. Jens Mueller's example passes now, but the other ones still fail.

--
March 24, 2016
https://issues.dlang.org/show_bug.cgi?id=5363

taylorh140@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |taylorh140@gmail.com

--- Comment #7 from taylorh140@gmail.com ---
Still fails on DMD 2.070.2 ( 2.070.2 )
http://dpaste.dzfl.pl/1da91ec34a86

--
September 18, 2018
https://issues.dlang.org/show_bug.cgi?id=5363

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nilsbossung@googlemail.com

--- Comment #8 from RazvanN <razvan.nitu1305@gmail.com> ---
*** Issue 9354 has been marked as a duplicate of this issue. ***

--
October 06, 2018
https://issues.dlang.org/show_bug.cgi?id=5363

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=6777

--
October 06, 2018
https://issues.dlang.org/show_bug.cgi?id=5363

--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> ---
I simplified it a bit more, so it happens at compile time:

  struct S {
    int dummy;
    alias dummy this;
  }
  int foo(int){ return 1; }
  int foo(const(S)){ return 2; }

  void test() {
    static assert(foo(cast(const)S.init) == 2); // pass
    static assert(foo(S.init) == 2); // fail
  }

Here's the trouble. With alias this, the conversion of S to int is considered an 'exact' match, while the conversion of S to const is considered a 'constant' match, which is not as good as 'exact'. Hence, the 'exact' is selected and foo(int) is called.

The levels of conversion are:

    nomatch
    convert
    constant
    exact

We could change an alias this conversion to a 'convert' match, but it is unknown how much breakage this will cause. It seems to be a rather drastic change.

The compiler source code is the TypeStruct.implicitConvTo() function in
mtype.d.

--
October 08, 2018
https://issues.dlang.org/show_bug.cgi?id=5363

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #10 from RazvanN <razvan.nitu1305@gmail.com> ---
PR : https://github.com/dlang/dmd/pull/8810

--
October 09, 2018
https://issues.dlang.org/show_bug.cgi?id=5363

calex <calex+bugzilla-mail@aristoweb.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |calex+bugzilla-mail@aristow
                   |                            |eb.net

--
October 19, 2018
https://issues.dlang.org/show_bug.cgi?id=5363

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=9274

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=5363

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P1

--