2 ms·
FTA, in the “ad hoc unions” section: “A value of an ad hoc union type can be implicitly coerced to another ad hoc union type if all member types of the source
by Someone 2y ago
FTA, in the “ad hoc unions” section:
“A value of an ad hoc union type can be implicitly coerced to another ad hoc union type if all member types of the source union type can be implicitly coerced to one of the member types of the target union type
(int or short) value = 10;
(float or double) value2 = value;
“
So, value2 is a (float or double), but is it a float or a double here for deconstruction? I guess they mean it to be a float if value were an int (which it is here, as 10 is a literal int) and a double if it were a short, but that implies there is an ordering in the union variants, and the way. I read it that is in conflict with
“Ad hoc unions with the same member types (regardless of order) are understood by the compiler to be the same type.
(A or B) x = new A(10, "ten");
(B or A) y = x;
Because we would have
(float or double) value2 = value; // value2 is a float
(double or float) value3 = value; // value3 is a double