lsp/sema: recognise the implicit 'context' global
context (the context system — context.allocator, context.data) was reported as an 'undefined variable'. It's now registered as a Context-typed global when Context is in scope, so the field chain (context.allocator) resolves too, with a builtins-list fallback when Context isn't present.
This commit is contained in:
@@ -118,6 +118,13 @@ pub const Analyzer = struct {
|
||||
try self.registerTopLevelDecl(decl);
|
||||
}
|
||||
|
||||
// Implicit `context` global (the context system — `context.allocator`,
|
||||
// `context.data`). Registered with its `Context` type when that's in
|
||||
// scope so the field chain resolves.
|
||||
if (self.struct_types.contains("Context")) {
|
||||
try self.addSymbol("context", .variable, .{ .struct_type = "Context" }, .{ .start = 0, .end = 0 });
|
||||
}
|
||||
|
||||
// Pass 2: Analyze bodies (all top-level names are now in scope).
|
||||
for (root.data.root.decls) |decl| {
|
||||
try self.analyzeTopLevelDecl(decl);
|
||||
@@ -854,7 +861,7 @@ pub const Analyzer = struct {
|
||||
}
|
||||
|
||||
// Built-in names that aren't declared in source
|
||||
const builtins = [_][]const u8{ "io", "true", "false", "cast", "closure", "out", "size_of", "align_of", "malloc", "free", "memcpy", "memset" };
|
||||
const builtins = [_][]const u8{ "io", "true", "false", "cast", "closure", "out", "size_of", "align_of", "malloc", "free", "memcpy", "memset", "context" };
|
||||
for (builtins) |b| {
|
||||
if (std.mem.eql(u8, name, b)) return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user