Thread overview
[Issue 17766] Wrong choice of generic mutable/const/immutable methods
Aug 20, 2017
ag0aep6g@gmail.com
Aug 21, 2017
ZombineDev
Dec 17, 2022
Iain Buclaw
August 20, 2017
https://issues.dlang.org/show_bug.cgi?id=17766

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |ag0aep6g@gmail.com

--
August 21, 2017
https://issues.dlang.org/show_bug.cgi?id=17766

ZombineDev <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov@gmail.com

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

alexandru.ermicioi@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alexandru.ermicioi@gmail.co
                   |                            |m

--- Comment #1 from alexandru.ermicioi@gmail.com ---
This is not the only case, here is another case of wrong selection:

----------------------
class Mquartz(T, Z) {
    Z pass(T component) const {
        "Mutable pass".writeln;
        return component.z;
    }
    const(Z) pass(const T component) const {
        "Const pass".writeln;
        return component.z;
    }
    const(Z) pass(immutable T component) const {
        "Immutable pass".writeln;
        return component.z;
    }
    const(Z) pass(inout T component) const {
        "Inout pass".writeln;
        return component.z;
    }
}

struct V {
    int z;
}

void main() {

    auto m = new Mquartz!(V, typeof(V.z));

    // V v = V(21);
    // writeln(m.pass(v));
    writeln(m.pass(V(20)));
    writeln(m.pass(const(V)(20)));
    writeln(m.pass(immutable(V)(20)));
    writeln(m.pass(inout(V)(20)));
}
-------------------------
Current logic will select only const version with const argument instead of selecting right ones:
-------------------------
Const pass
20
Const pass
20
Const pass
20
Const pass
20
-------------------------
The overload selection logic works as expected only if m is const, then response will as expected:
-------------------------
Mutable pass
20
Const pass
20
Immutable pass
20
Inout pass
20
-------------------------

--
April 12, 2019
https://issues.dlang.org/show_bug.cgi?id=17766

Илья Ярошенко <ilyayaroshenko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

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

--