Open topolarity opened 2 years ago
Wanted to file this to follow-up on the discussion in https://github.com/ziglang/zig/pull/12826
A possible solution was proposed in that PR: Make this a question of type inference rather than coercion, by allowing &.{...}
to coerce to the type of its result location, but not allowing this for any tuple pointer created after the fact.
In that case, there is no tuple pointer to alias against at all. We are essentially inferring that .{...}
should have been an array from the beginning.
These concerns were brought up when this coercion was initially implemented and if only allowing &.{}
gets rid of them then we should go with that since &.{}
is the only intended use case in the first place (at least IMO).
Note that as of #16512, this coercion is not used for the &.{ ... }
case. Also note that the accepted proposal #16865 eliminates anonymous struct types entirely, so implicitly removes this coercion.
Zig Version
0.10.0-dev.1246+e67c756b91
Steps to Reproduce and Observed Behavior
Both tests fail
Expected Behavior
Both of these behaviors are incongruous with how reference semantics typically work in Zig. In every other pointer-to-pointer cast (implicit or explicit), aliasing is respected and the valid lifetime of the created pointer is the same as the pointer being cast from.