On Tuesday, 31 August 2021 at 05:42:22 UTC, ag0aep6g wrote:
On 31.08.21 02:50, Mike Parker wrote:
Member functions marked as immutable can be called on both mutable and immutable instances.

That's not true.

Demonstrated:

```d
struct S {
    int x;
    int get() immutable { return x; }
}

unittest {
    auto s1 = S(1);
    const s2 = S(2);
    immutable s3 = S(3);
assert(s1.get == 1); // Error: is not callable using a mutable object assert(s2.get == 2); // Error: is not callable using a `const` object
    assert(s3.get == 3);
}
```

s/immutable/const/ and all those uses are acceptable.

Reply via email to