Open iacore opened 8 months ago
This ties into language design questions around RLS coercions with lvalues. The issue is essentially that we want @as(*const Nat, &Nat.Z)
to coerce Z
to the union type (from the tag type), but we don't want this for e.g. @as(*const Nat, &my_aggregate.nat_field)
which is an indistinguishable syntax form.
Making this work is therefore a language proposal.
In https://ziglang.org/documentation/master/#toc-Type-Coercion-Unions-and-Enums, it says
Tagged unions can be coerced to enums, and enums can be coerced to tagged unions when they are comptime-known to be a field of the union that has only one possible value, such as void:
By this logic only comptime-known <A>
will be coerced in expression &A
.
Yes, if this is implemented it can only work for comptime-known values in this specific case, but that's not relevant to the proposal. The proposal is to perform coercions of certain lvalue expressions as rvalues so as to make this code work.
Zig Version
0.12.0-dev.2818+97290e0bf
Steps to Reproduce and Observed Behavior
save this file as
inductive.zig
error:
Expected Behavior
The syntax should work, I think.
Workaround