Files
sx/examples/0158-types-reserved-name-member-exempt.sx
agra d8076b9333 lang: rename signed integer types sN -> iN
Surface rename of the signed integer family: s1..s64 become i1..i64
(u1..u64, usize, isize unchanged). 'string' keeps the s-prefix arm in
name classification; width parsing moves to the i-prefix arm next to
isize.

Internal TypeId tags follow the surface (.s8/.s16/.s32/.s64 ->
.i8/.i16/.i32/.i64), as do mono-key mangle fragments (ptr_i64,
tu_i64_bool) and all display/diagnostic formatting (i{d}).

Migrated in the same sweep: stdlib + examples + issue repros + FFI C
companions (shared symbol names like ffi_id_i64), expected
stdout/stderr/ir snapshots, specs.md, readme.md, CLAUDE.md/AGENTS.md,
implementation_plan.md, docs/, issue writeups. Vendored stb_image and
historical flow state left untouched.

zig build test: 426/426; examples suite: 595/595.
2026-06-12 09:31:53 +03:00

56 lines
2.1 KiB
Plaintext

// Reserved-name MEMBER positions are EXEMPT from the reserved-type-name rule:
// a bare reserved spelling (`i2`, `u8`, `i1`, …) 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.`i2`) and bare access (`obj.i2`) 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 (`` `i2 :: (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 {
i2: i64;
u8: i64;
}
// Union tags spelled with reserved type names — bare is legal.
Tag :: union {
i1: i32;
u16: f64;
}
// Protocol method SIGNATURE spelled with a reserved type name — bare is legal.
Speaker :: protocol {
i2 :: () -> i64;
}
Dog :: struct { n: i64; }
impl Speaker for Dog {
`i2 :: (self: *Dog) -> i64 { self.n } // impl DEFINITION → backtick required
}
main :: () -> i32 {
h := Holder.{ i2 = 10, u8 = 20 };
print("fields bare = {} {}\n", h.i2, h.u8); // bare member access
print("fields tick = {} {}\n", h.`i2, h.`u8); // backtick member access
h.i2 = 11;
h.`u8 = 21; // backtick write
print("fields set = {} {}\n", h.i2, h.u8);
t : Tag = ---;
t.i1 = 5;
print("union = {} {}\n", t.i1, t.`i1); // bare + backtick — same tag
items : List(Speaker) = .{};
items.append(Dog.{ n = 7 });
print("dispatch = {}\n", items.items[0].i2()); // bare reserved-name method call
return 0;
}