digitalmars.D - Const hole
- Steven Schveighoffer (20/20) May 14 2022 I accidentally found that I was implicitly casting in my code a const
- bauss (5/25) May 16 2022 And the one pull request that should've fixed it has been closed
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
May 14 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 } ``` -SteveAnd 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
May 16 2022