-
Key: DDSXTY14-107
-
Status: open
-
Source: Real-Time Innovations ( Dr. Gerardo Pardo-Castellote, Ph.D.)
-
Summary:
The assignability rules for unions require matching or the member_id. By default these are assigned sequentially so a union that just reorders the cases becomes incompatible.
This seems overly restrictive.
For non-mutable unions, the value of the memberId is never serialized so there is no reason it should influence the type assignability. Considering it just makes unions brittle without providing any extra safely as this is already provided by the discriminator value.For mutable unions we are serializing the memberId ahead of the member. However, when it comes to deserializing the member that will hold the value is can be selected by the value of the discriminator. We could also use the memberId since it is available, but it is unclear what benefit that would carry.
The current union assignability rules for assigning T1 from T2 require that members with the same ID has the same name and members with the same name have the same ID. However they do not require that the members selected in T1 and T2 for a give value of the discriminator have the same ID or name. They just need to be assignable.
For example the unions T1 and T2 are assignable:
union T1 switch (int32) { case 1: @id(10) int32 x; case 2: @id(20) int64 y; }; union T2 switch (int32) { case 1: @id(30) int32 xx; case 2: @id(40) int64 yy; };
However the unions T3 and T4 are not assignable
union T3 switch (int32) { case 1: int32 x; case 2: int64 y; }; union T4 switch (int32) { case 1: int32 xx; case 2: int64 yy; };
Given this, it seems like considering the memberId as part of assignability makes the union brittle and harder to extend. Without providing additional protection. Specially given that by default member IDs are assigned sequentially.
Changing serialization rules for mutable unions would break existing systems. So it seems we should keep serializing the member ID. However we could relax compatibility rules to make unions easier to extend.
(1) For final/appendable unions. we could just remove the condision on member ID. They would just be ignored as well as member names. As long the member selected by the discriminator has assignable types it would be enough.
Alternatively, If we want additional protection, we could we could require that any non-default member selected in T1 has the same name as the member selected in T2. We could also say that if the members do not have the same name, then we check the ID and if the ID matches then we allow it. This would allow changing names as long as the ID is kept the same. But the benefit is not so clear given IDs are assigned sequentially by default. So we might want to combine this with assigning IDs as HASH by default.
(2) For mutable unions, We could either ignore IDs and names (similar than final/appendable) or we could default to using @autoid("HASH")
As long as we change assignability rules to be more lenient it should not break existing systems s.
-
Reported: DDS-XTypes 1.3b1 — Tue, 26 Aug 2025 16:19 GMT
-
Updated: Tue, 16 Sep 2025 01:36 GMT
DDSXTY14 — Assignability riles for unions are brittle and restrictive
- Key: DDSXTY14-107
- OMG Task Force: DDS Extensible Types (DDS-XTYPES) 1.4 RTF