feat(C3.1): #foreign refs are validated — must name a #library or a named #import c unit

validateForeignRefs walks the merged tree (libraries + named c units,
nested namespaces included) and diagnoses any #foreign whose ref names
neither — a typo'd ref previously compiled and resolved silently
through whatever image carried the symbol. Decls synthesized from
#include headers carry no ref and are exempt. Flips the C0.2b pin;
zero collateral across the 608 other examples.
This commit is contained in:
agra
2026-06-12 17:09:07 +03:00
parent 0bd8f3e5ce
commit 1bad29e72e
6 changed files with 70 additions and 9 deletions

View File

@@ -298,6 +298,13 @@ pub const Compilation = struct {
/// Lower the parsed AST to the sx IR module (shadow pipeline).
pub fn lowerToIR(self: *Compilation) !ir.Module {
const root = self.resolved_root orelse self.root orelse return ir.Module.init(self.allocator);
// Every `#foreign <ref>` must name a #library constant or a named
// `#import c` unit — a typo'd ref otherwise resolves silently
// through whatever image happens to carry the symbol.
try c_import.validateForeignRefs(self.allocator, root, &self.diagnostics);
if (self.diagnostics.hasErrors()) return error.CompileError;
var module = ir.Module.init(self.allocator);
//TODO: find a better place for this
if (self.target_config.isWasm32()) {