Const hole
bauss
jj_1337 at live.dk
Mon May 16 11:53:42 UTC 2022
On Sunday, 15 May 2022 at 02:41:34 UTC, Steven Schveighoffer
wrote:
> I accidentally found that I was implicitly casting in my code a
> const vibed Json type to a mutable Json type.
>
> I thought "that can't be right, how does that even work?
> Especially if the Json is an object or an array!".
>
> But it does. At least since 2014.
>
> See https://issues.dlang.org/show_bug.cgi?id=12885
>
> Enjoy a nice cast-free way to use sumtype to unconstify
> references in @safe code!
>
> ```d
> import std.sumtype;
>
> void main() @safe
> {
> alias MyType = SumType!(int, char[]);
> auto mt = const(MyType)("hello");
> MyType m2 = mt;
> char[] result = m2.tryMatch!((char[] a) => a);
> result[0] = 'j'; // segfault
> }
> ```
>
> -Steve
And the one pull request that should've fixed it has been closed
(not merged) and with no further update or explanation.
https://github.com/dlang/dmd/pull/9061
More information about the Digitalmars-d
mailing list