Thread overview
[Issue 13628] Error: immutable method S.~this is not callable using a mutable object and vice versa
Oct 19, 2014
Marco Leise
Jun 11, 2015
Maxim Fomin
Jun 11, 2015
Marco Leise
Jun 11, 2015
Maxim Fomin
Jun 11, 2015
Marco Leise
Jun 14, 2015
Marc Schütz
Dec 20, 2021
anonymous4
Dec 17, 2022
Iain Buclaw
Mar 01, 2023
RazvanN
October 19, 2014
https://issues.dlang.org/show_bug.cgi?id=13628

--- Comment #1 from Marco Leise <Marco.Leise@gmx.de> ---
Reduced test case:

struct B {
    ~this() { /* some cleanup */ }
}

struct C {
    immutable B b;
}

void main() {
    C(immutable B());
}

--
June 11, 2015
https://issues.dlang.org/show_bug.cgi?id=13628

Maxim Fomin <maxim-fomin@outlook.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |maxim-fomin@outlook.com
         Resolution|---                         |INVALID

--- Comment #2 from Maxim Fomin <maxim-fomin@outlook.com> ---
It is by design. You must make destructor immutable to call it for immutable object. Closed as invalid.

--
June 11, 2015
https://issues.dlang.org/show_bug.cgi?id=13628

--- Comment #3 from Marco Leise <Marco.Leise@gmx.de> ---
You can't just close this without further discussion. That is disrespectful given the three questions I had refer to my failed attempts at doing what you propose as a solution.

--
June 11, 2015
https://issues.dlang.org/show_bug.cgi?id=13628

Maxim Fomin <maxim-fomin@outlook.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---
           Severity|major                       |normal

--- Comment #4 from Maxim Fomin <maxim-fomin@outlook.com> ---
A) It does not call opposite dtor. It tries to call mutable dtor for mutable object. In other words, it tries to pass immutable object as argument for mutable lvalue parameter. It cannot work.

B) Then it means that currently there is no way to define two dtors which differ by this pointer qualifier. So, it is another problem with D type system. I think it should be possible to do, and compiler should select proper overload.

C) Basically it is same as b.

I suggest to reopen as request to fix b.

--
June 11, 2015
https://issues.dlang.org/show_bug.cgi?id=13628

--- Comment #5 from Marco Leise <Marco.Leise@gmx.de> ---
Thanks. B) really is what was bugging me. You can have either type of dtor, but not both, making it impossible to have structs with dtors as both mutable and immutable.

--
June 14, 2015
https://issues.dlang.org/show_bug.cgi?id=13628

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

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

--
December 18, 2021
https://issues.dlang.org/show_bug.cgi?id=13628

feklushkin.denis@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |feklushkin.denis@gmail.com

--
December 20, 2021
https://issues.dlang.org/show_bug.cgi?id=13628

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec

--- Comment #6 from anonymous4 <dfj1esp02@sneakemail.com> ---
In the meantime behavior was changed for simplicity or something like that, now unqualified destructor is always called on unqualified instance, like this:

struct SecureString
{
    char[] secret;
    ~this() { secret[]=0; }
}

int main()
{
    immutable s=immutable SecureString("aa");
    return 0;
}

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
March 01, 2023
https://issues.dlang.org/show_bug.cgi?id=13628

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |MOVED

--- Comment #7 from RazvanN <razvan.nitu1305@gmail.com> ---
The original report has been fixed as the test case compiles successfully. As for the matter of overloading dtors, there are other issues that represent this problem.

--