On Tuesday, 22 December 2020 at 14:27:02 UTC, ag0aep6g wrote:
On 22.12.20 04:56, 9il wrote:
6. Algebraic type subsets are supported by `get`, `trustedGet`, `_is`, and `this` primitives. You can operate with algebraic subset as with the type of the original typeset. [1]

"trustedGet" - That name smells of a safety violation. And indeed (compile with `-release`):

----
import mir.algebraic;
import std.stdio;
void main() @safe
{
    immutable int* x = new int(42);
    Variant!(size_t, int*) v;
    v = cast(size_t) x;
    auto p = v.trustedGet!(int*); /* uh-oh */
    *p = 13; /* mutating immutable */
    writeln(*x); /* prints "13" */
}
[snip]

For
v = cast(size_t) x;
I thought @safe prevented explicitly casting an immutable to a mutable, but the code below seems to suggest it is ok in this case...

void main() @safe
{
    immutable x = 32;
    auto v = cast(size_t) x;
}

Reply via email to