Closed novusnota closed 1 month ago
One would expect for fields of
Add
to be automatically coerced with fields ofAddOk
, as they're named the same, have identical types and are layed out in the same order.
I'm not sure if we need this. It doesn't even work this way in Typescript (the following snippet doesn't compile):
type Test = {
x: number;
y: number;
}
const a: Test = {
x: 123,
y: 234,
};
const b: Test = {
a.x,
a.y
}
}
Let me close this for now. Punning is not supposed to work with expressions that are not identifiers.
Consider the following example:
One would expect for fields of
Add
to be automatically coerced with fields ofAddOk
, as they're named the same, have identical types and are layed out in the same order.We may also consider making values of such 1-to-1 mapped types to be directly assignable to each other (duck typing of sorts), like:
Although I'm not sure about the use case and bug-freeness of such approach, so just making struct field punning one level deeper than it is now would be more than enough.