"Jeremie Pelletier" <jerem...@gmail.com> wrote in message news:h9mmre$1i8...@digitalmars.com... > Ary Borenszweig wrote: >> >> Object is not-nullable, Object? (or whatever syntax you like) is >> nullable. So that line is a compile-time error: you can't cast a null to >> an Object (because Object *can't* be null). >> > > union A { > Object foo; > Object? bar; > } > > Give me a type system, and I will find backdoors :) >
Unions are nothing more than an alternate syntax for a reinterpret cast. And it's an arguably worse syntax because unlike casts, uses of it are indistinguishable from normal safe code, there's nothing to grep for. As such, unions should never be considered any more safe than cast(x)y. The following is just as dangerous as your example above and doesn't even touch the issue of nullability/non-nulability: union A { int foo; float bar; }