Reserved type-name spellings (s1, s2, u8, …) can now be used as value identifiers two ways, resolving issue 0089: 1. Backtick raw identifier: a leading backtick (`s2) lexes to an .identifier token carrying a new Token.is_raw flag, with the backtick excluded from the text. A raw identifier is never type-classified — the parser skips Type.fromName for it — so it is always a value identifier. The flag threads to VarDecl.is_raw / Param.is_raw at binding sites, and the reserved-type-name check (UnknownTypeChecker) skips raw bindings. Because the token tag stays .identifier, the escape works in every position (local, global, param, field, fn name, struct member, later reference) with no per-site parser change. 2. #import c exemption: c_import.zig synthesizes foreign decls with Param.is_raw = true, so generated C param names that collide with reserved type names (s1, s2) import unedited. A bare reserved-name binding in sx still errors (issue 0076 preserved): the is_raw-gated skip only fires for backtick / foreign names, and a raw binding's address-of / autoref lowering stays correct because every occurrence is an .identifier, never a .type_expr. Tests: examples/0151 (backtick, every position), examples/1220 (foreign exemption, compiled+run), lexer unit tests. 1119 (bare-binding rejection) stays green. specs.md + readme.md updated.
21 lines
822 B
Plaintext
21 lines
822 B
Plaintext
// `#import c` foreign-name exemption: a C header's parameter names `s1`/`s2`
|
|
// collide with sx's reserved signed-int type spellings. Foreign decls are
|
|
// treated as RAW — their names are never type-classified nor reserved-checked
|
|
// — so the generated `#foreign` bindings import and call without hand-edits
|
|
// (no backticks needed). Before issue 0089 this errored with "'s1' is a
|
|
// reserved type name and cannot be used as an identifier".
|
|
// Regression (issue 0089).
|
|
#import "modules/std.sx";
|
|
|
|
#import c {
|
|
#include "1220-ffi-c-import-reserved-name-params.h";
|
|
#source "1220-ffi-c-import-reserved-name-params.c";
|
|
};
|
|
|
|
main :: () -> s32 {
|
|
print("pick(10,20,0) = {}\n", ffi_pick(10, 20, 0));
|
|
print("pick(10,20,1) = {}\n", ffi_pick(10, 20, 1));
|
|
print("sum(10,20) = {}\n", ffi_sum(10, 20));
|
|
0
|
|
}
|