AGRA RULING (issue 0089, attempt 7): bare reserved-name MEMBER positions are intentionally exempt from the reserved-type-name rule, and the implementation already does the right thing — this is a docs + one-example change, no code. The exempt member positions are struct FIELD names, union TAG names, and protocol method-SIGNATURE names: they sit in a member slot, are reached via obj.name (or dispatched by string), and are never type-classified, so they never mis-lower. The backtick is optional there. The exemption stops at member DEFINITIONS: an impl method is a real function (reached through the impl_block -> fn_decl arm), so a reserved-spelled impl method still needs the backtick, exactly like a free function (cf. examples/1122) — and every bare reserved-name value binding / declaration name still errors (0076 preserved). - specs.md / readme.md: replace the "every binding site" / "any binding site" overclaim with the precise rule — required positions (value bindings + declaration names + impl method definitions) vs the exempt member-name positions (field / tag / protocol signature; backtick optional). - examples/0158-types-reserved-name-member-exempt.sx: pins the exempt behavior — bare reserved-name struct fields + union tag read & written bare AND via backtick, and a protocol with a bare reserved-name method dispatched through the protocol (impl definition takes the backtick). - issues/0089: document the member-name exemption in the RESOLVED banner + add 0158 to the regression list. Gate: zig build, zig build test, bash tests/run_examples.sh — all green (430 passed, 0 failed, 0 timed out).
56 lines
2.1 KiB
Plaintext
56 lines
2.1 KiB
Plaintext
// Reserved-name MEMBER positions are EXEMPT from the reserved-type-name rule:
|
|
// a bare reserved spelling (`s2`, `u8`, `s1`, …) is legal as a struct FIELD
|
|
// name, a union TAG name, and a protocol METHOD-SIGNATURE name. These are
|
|
// unambiguous — the name sits in a member slot and is reached via `obj.name`
|
|
// (or dispatched by string), so it is never type-classified and never
|
|
// mislowers. The backtick form is optional there and resolves to the same
|
|
// member. Backtick access (`obj.`s2`) and bare access (`obj.s2`) both work.
|
|
//
|
|
// The exemption stops at member SIGNATURES: an `impl` method DEFINITION is a
|
|
// real function, so its name is a declaration site (like a free function) and a
|
|
// reserved spelling still needs the backtick (`` `s2 :: (self) ``) — bare would
|
|
// be type-classified and mislower (the issue-0076 protection). A bare reserved
|
|
// VALUE binding / declaration name still errors (see examples/1119, 1141, 1142).
|
|
// Regression (issue 0089 — attempt-7: pins the Agra-ruled member-name exemption).
|
|
#import "modules/std.sx";
|
|
|
|
// Struct fields spelled with reserved type names — bare is legal.
|
|
Holder :: struct {
|
|
s2: s64;
|
|
u8: s64;
|
|
}
|
|
|
|
// Union tags spelled with reserved type names — bare is legal.
|
|
Tag :: union {
|
|
s1: s32;
|
|
u16: f64;
|
|
}
|
|
|
|
// Protocol method SIGNATURE spelled with a reserved type name — bare is legal.
|
|
Speaker :: protocol {
|
|
s2 :: () -> s64;
|
|
}
|
|
|
|
Dog :: struct { n: s64; }
|
|
impl Speaker for Dog {
|
|
`s2 :: (self: *Dog) -> s64 { self.n } // impl DEFINITION → backtick required
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
h := Holder.{ s2 = 10, u8 = 20 };
|
|
print("fields bare = {} {}\n", h.s2, h.u8); // bare member access
|
|
print("fields tick = {} {}\n", h.`s2, h.`u8); // backtick member access
|
|
h.s2 = 11;
|
|
h.`u8 = 21; // backtick write
|
|
print("fields set = {} {}\n", h.s2, h.u8);
|
|
|
|
t : Tag = ---;
|
|
t.s1 = 5;
|
|
print("union = {} {}\n", t.s1, t.`s1); // bare + backtick — same tag
|
|
|
|
items : List(Speaker) = .{};
|
|
items.append(Dog.{ n = 7 });
|
|
print("dispatch = {}\n", items.items[0].s2()); // bare reserved-name method call
|
|
return 0;
|
|
}
|