feat(lang): raw provenance through ALL sema compound type metadata — finish universal raw identifier in the LSP classifier [F0.6]
The codegen-side resolver was already raw-aware for the universal model; the sema/LSP editor index (the second classifier) only honored the DIRECT raw type. A COMPOUND raw type (`*`s2`, `?`s2`, `[N]`s2`, `[]`s2`, `[*]`s2`) stores its inner type-name as a bare string on the Type info struct, and every resolution site re-read it with skip_builtin=false — so the index reclassified a user type named `s2` as the builtin int, diverging from codegen (issue-0083 class, LSP surface only; codegen unchanged). Structural cure: every compound info struct (Pointer/Optional/Slice/ ManyPointer/Array) carries a REQUIRED is_raw bit (no default — a future construction site cannot drop it). is_raw is set at every construction site (resolveTypeNode arms, fieldType arms, variadic slice, .ptr/slice_expr derivation, for-loop by-ref, substType) and passed as skip_builtin at every resolution site (elementTypeOf, field-access pointer unwrap, index, deref, optional unwrap/null-coalesce, if/while optional binding, match subject). Optional-unwrap + deref sites converted from Type.fromName/pointerPointeeType (builtin-only, divergent) to resolveTypeNameStr(name, is_raw); the now-dead pointerPointeeType removed. Tests: src/sema.test.zig gains pointer/optional/array raw-vs-bare regressions (raw → user type, bare → builtin control) — each FAILS on pre-fix sema, PASSES after — plus a parameterized-raw coverage test.
This commit is contained in:
@@ -84,3 +84,132 @@ test "sema: a raw struct-field annotation resolves to the user type; bare stays
|
||||
try std.testing.expect(b_ty.? == .unsigned);
|
||||
try std.testing.expectEqual(@as(u8, 8), b_ty.?.unsigned);
|
||||
}
|
||||
|
||||
// ── issue 0089: raw provenance through sema's COMPOUND type metadata ────────
|
||||
//
|
||||
// The direct-case fix (above) only covered a bare `` `s2 `` reference. A
|
||||
// COMPOUND raw type (`*`s2`, `?`s2`, `[N]`s2`, …) stores its inner name as a
|
||||
// bare string on the Type's info struct; the resolver re-reads that name via
|
||||
// `resolveTypeNameStr`. Before threading `is_raw` ALONGSIDE the stored name,
|
||||
// the resolver passed `skip_builtin = false`, so the LSP index reclassified a
|
||||
// user type named `s2` as the builtin int — diverging from codegen. These
|
||||
// pin every compound form: the raw inner resolves to the user type (FAILS on
|
||||
// pre-fix sema), the bare inner stays the builtin (control, preserved).
|
||||
|
||||
fn symType(res: sema.SemaResult, name: []const u8) ?Type {
|
||||
for (res.symbols) |sym| {
|
||||
if (std.mem.eql(u8, sym.name, name)) return sym.ty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
test "sema: field access through a raw `*`s2` pointer resolves the user field; bare `*s2` stays builtin" {
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
const src =
|
||||
\\`s2 :: struct { x: s64; }
|
||||
\\f :: (p: *`s2) { y := p.x; }
|
||||
\\g :: (q: *s2) { w := q.*; }
|
||||
\\
|
||||
;
|
||||
var parser = Parser.init(alloc, src);
|
||||
const root = try parser.parse();
|
||||
var analyzer = sema.Analyzer.init(alloc);
|
||||
const res = try analyzer.analyze(root);
|
||||
|
||||
// RAW: `p: *`s2` → field `x` on the user struct → s64. (Pre-fix: the
|
||||
// pointee `s2` reclassified to the 2-bit int, `.x` not found → unresolved.)
|
||||
const y = symType(res, "y") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(y == .signed);
|
||||
try std.testing.expectEqual(@as(u8, 64), y.signed);
|
||||
|
||||
// CONTROL: `q: *s2` (bare) → deref yields the builtin 2-bit signed int.
|
||||
const w = symType(res, "w") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(w == .signed);
|
||||
try std.testing.expectEqual(@as(u8, 2), w.signed);
|
||||
}
|
||||
|
||||
test "sema: unwrapping a raw `?`s2` optional resolves the user field; bare `?s2` stays builtin" {
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
const src =
|
||||
\\`s2 :: struct { x: s64; }
|
||||
\\f :: (o: ?`s2) { if val := o { y := val.x; } }
|
||||
\\g :: (b: ?s2) { if v := b { w := v; } }
|
||||
\\
|
||||
;
|
||||
var parser = Parser.init(alloc, src);
|
||||
const root = try parser.parse();
|
||||
var analyzer = sema.Analyzer.init(alloc);
|
||||
const res = try analyzer.analyze(root);
|
||||
|
||||
// RAW: `o: ?`s2` → `if val := o` unwraps to the user struct → `val.x` is s64.
|
||||
// (Pre-fix: the optional child `s2` reclassified to the 2-bit int.)
|
||||
const y = symType(res, "y") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(y == .signed);
|
||||
try std.testing.expectEqual(@as(u8, 64), y.signed);
|
||||
|
||||
// CONTROL: `b: ?s2` (bare) unwraps to the builtin 2-bit signed int.
|
||||
const w = symType(res, "w") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(w == .signed);
|
||||
try std.testing.expectEqual(@as(u8, 2), w.signed);
|
||||
}
|
||||
|
||||
test "sema: indexing a raw `[N]`s2` array resolves the user element; bare `[N]s2` stays builtin" {
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
const src =
|
||||
\\`s2 :: struct { x: s64; }
|
||||
\\f :: (a: [4]`s2, b: [4]s2) { y := a[0]; w := b[0]; }
|
||||
\\
|
||||
;
|
||||
var parser = Parser.init(alloc, src);
|
||||
const root = try parser.parse();
|
||||
var analyzer = sema.Analyzer.init(alloc);
|
||||
const res = try analyzer.analyze(root);
|
||||
|
||||
// RAW: `a: [4]`s2` → element is the user struct. (Pre-fix: reclassified to
|
||||
// the 2-bit int.)
|
||||
const y = symType(res, "y") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(y == .struct_type);
|
||||
try std.testing.expectEqualStrings("s2", y.struct_type);
|
||||
|
||||
// CONTROL: `b: [4]s2` (bare) → element is the builtin 2-bit signed int.
|
||||
const w = symType(res, "w") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(w == .signed);
|
||||
try std.testing.expectEqual(@as(u8, 2), w.signed);
|
||||
}
|
||||
|
||||
// Parameterized raw type (`` `s2(s64) ``). Unlike the shapes above this never
|
||||
// had the divergence — instantiation resolves the base name straight against
|
||||
// `struct_types` (no builtin classifier in the path), so it passes before AND
|
||||
// after. Included as coverage that the universal model holds for the
|
||||
// parameterized form too: a `` `s2 ``-declared generic instantiates and its
|
||||
// field resolves.
|
||||
test "sema: a raw parameterized type `` `s2(s64) `` instantiates the user generic" {
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
const src =
|
||||
\\`s2 :: struct ($T: Type) { items: [*]T = null; n: s64 = 0; }
|
||||
\\f :: (v: `s2(s64)) { y := v.n; }
|
||||
\\
|
||||
;
|
||||
var parser = Parser.init(alloc, src);
|
||||
const root = try parser.parse();
|
||||
var analyzer = sema.Analyzer.init(alloc);
|
||||
const res = try analyzer.analyze(root);
|
||||
|
||||
// `v: `s2(s64)` instantiates the `` `s2 ``-declared generic; its concrete
|
||||
// field `n` resolves to s64 (the raw base name was not misread as a builtin).
|
||||
const y = symType(res, "y") orelse return error.MissingSymbol;
|
||||
try std.testing.expect(y == .signed);
|
||||
try std.testing.expectEqual(@as(u8, 64), y.signed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user