From 847468938b6b0bb858ac4cfa99bb56a7e82cc50f Mon Sep 17 00:00:00 2001 From: agra Date: Sun, 31 May 2026 12:15:21 +0300 Subject: [PATCH] lsp/sema: recognise the implicit 'context' global MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/sema.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sema.zig b/src/sema.zig index b099155..0a1c593 100644 --- a/src/sema.zig +++ b/src/sema.zig @@ -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; }