Move examples/*.sx and their expected/ snapshots into per-category subfolders (examples/<category>/...). Folder = leading filename token, with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus runner and LSP sweep now discover each category's expected/ dir, while issues/ stays flat. Example 1058's repo-root-relative companion import is made file-relative. Path strings embedded in 164 snapshots were regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
43 lines
1.6 KiB
Plaintext
43 lines
1.6 KiB
Plaintext
// Backtick raw identifier in TYPE position (the universal model, issue 0089):
|
|
// `` `name `` is the LITERAL identifier `name` used as a type reference, never
|
|
// the builtin/reserved spelling. A reserved type spelling (`i2`, `u8`, …) can
|
|
// therefore both DECLARE a type (struct / enum / union / error-set / alias) and
|
|
// be REFERENCED as that type via the backtick — while a BARE `i2` in type
|
|
// position remains the signed-int type (see `add` below) and a bare reserved-
|
|
// name declaration still errors (see examples/1141). The backtick is required
|
|
// to declare or reference these names; it is never part of the name's text.
|
|
// Regression (issue 0089 — attempt-4 universal raw identifier).
|
|
#import "modules/std.sx";
|
|
|
|
// Type-introducing decls whose NAME is a reserved spelling.
|
|
`i2 :: struct { x: i64; }
|
|
`i8 :: enum { A; B; }
|
|
`u16 :: union { i: i32; f: f32; }
|
|
`u32 :: error { Bad, Empty }
|
|
RawAlias :: `i2; // alias to a backtick-declared struct
|
|
|
|
// A bare `i2` in type position is still the 2-bit signed int.
|
|
add :: (a: i2, b: i2) -> i2 { return a + b; }
|
|
|
|
main :: () -> i32 {
|
|
// Reference the backtick struct as a type; field access works.
|
|
v : `i2 = ---;
|
|
v.x = 7;
|
|
|
|
// Reference via a normal alias too.
|
|
a : RawAlias = ---;
|
|
a.x = 11;
|
|
|
|
// Backtick enum / union type references.
|
|
e : `i8 = .A;
|
|
u : `u16 = ---;
|
|
u.i = 5;
|
|
|
|
print("struct = {}\n", v.x);
|
|
print("alias = {}\n", a.x);
|
|
print("enum = {}\n", e == .A);
|
|
print("union = {}\n", u.i);
|
|
print("bare = {}\n", add(1, 0)); // bare i2 = the 2-bit int type
|
|
return 0;
|
|
}
|