Dealing with the interior pointers bug
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 22 12:37:27 PDT 2017
On 06/22/2017 08:38 PM, Boris-Barboris wrote:
> Casts are part of the type system. Yes, D type system allows invalid
> operations. It's not the compiler's fault, it's type system's fault.
>
> unittest
> {
> immutable int a = 4;
> int* b = cast(int*) &a;
> *b = 5;
> assert(*(&a) == 5);
> assert(a == 4);
> }
This is just arguing semantics, of course, but I wouldn't say that the
type system allows this specific invalid operation. Rather, with casting
you can step out of the type system, and break its guarantees.
Point is, you need a way to say that the operation is invalid. It's
invalid because it breaks what `immutable` promises. `immutable` is part
of the type, so I'd say the guarantee is part of the type system.
More information about the Digitalmars-d-learn
mailing list