July 30, 2022
On 7/30/22 15:19, Salih Dincer wrote:
> On Saturday, 30 July 2022 at 10:02:50 UTC, Timon Gehr wrote:
>>
>> It's a `const` hole, plain and simple.
> 
> This code, which consists of 26 lines, does not compile in DMD 2.087.  I am getting this error:
> 
>> constHole.d(15): Error: mutable method `source.Updater.opCall` is not callable using a `const` object
> constHole.d(15):        Consider adding `const` or `inout` to source.Updater.opCall
> constHole.d(21): Error: function `source.Updater.opCall(string s)` is not callable using argument types `(string*)`
> constHole.d(21):        cannot pass argument `&s.s` of type `string*` to parameter `string s`
> 
> SDB@79

Exactly. This is my point. This code does not compile, and neither should the original version, because it's doing basically the same thing.
July 30, 2022

On Saturday, 30 July 2022 at 10:34:09 UTC, ag0aep6g wrote:

>

You're not making sense. Your s is mutable, not immutable.

You're right! I saw the hole at the end of the tunnel late 😀

But if you compile the example below without the new operator, the system does not work and does not give any errors. Why?

Voldermort Type Version:

auto imstr(string str) pure @safe
{
  struct IMSTR
  {
    string s;
    void delegate(string s) @safe update;
    string toString() const { return s; }
  }
  auto s = new IMSTR(str);
       s.update = (_) { s.s = _; };
  return s;
}

import std.stdio;
void main() @safe
{
  immutable auto str = imstr("Test 123");
  //str.s = "test";

  str.toString.writeln;
  str.update("TEST A");

  str.toString.writeln;
  str.update("TEST B");

  str.toString.writeln;
  typeid(str).writeln;

}/* Prints:
Test 123
TEST A
TEST B
immutable(immutable(onlineapp.imstr(immutable(char)[]).IMSTR)*)
*/

SDB@79

1 2
Next ›   Last »