DIP 1017--Add Bottom Type--Final Review
Neia Neutuladh
neia at ikeran.org
Tue Jan 22 16:09:39 UTC 2019
On Tue, 22 Jan 2019 12:57:10 +0000, Olivier FAURE wrote:
> On Monday, 21 January 2019 at 17:52:52 UTC, Neia Neutuladh wrote:
>> The more extreme variant, where everything is a tuple that implicitly
>> casts to any prefix of itself, is not very useful.
>
> Why?
Because it makes field order significant. It means that these two types
are different:
struct A { int x; string y; }
struct B { string y; int x; }
The first is Tuple!(int, string); the second is Tuple!(string, int). They
look like they should convert to each other, but they don't.
And these two types *do* convert to each other, but not in the way you'd
want:
struct A { bool destroyEarth; bool preserveHumanity; }
struct B { bool preserveHumanity; bool destroyEarth; }
Passing the wrong type flips the fields around, because the order of the
fields is what matters, because that's part of the structure. And that's
why nobody actually suggests this.
More information about the Digitalmars-d
mailing list