fix: diagnose unknown generic #builtin instead of silently returning 0 (issue 0144)

A bodiless #builtin with a $T: Type param routes through monomorphization.
When resolveBuiltin returned null for an unrecognized name, the builtin-body
branch fell through to ensureTerminator's constInt(0) -- a silent-fallback
default the CLAUDE.md REJECTED PATTERNS forbid. Emit a loud
'error: unknown #builtin <name>' diagnostic instead.

Regression: examples/1189-diagnostics-unknown-builtin.sx
This commit is contained in:
agra
2026-06-21 09:10:38 +03:00
parent 6ed29621ad
commit ad45ae07ef
6 changed files with 41 additions and 0 deletions

View File

@@ -152,6 +152,16 @@ pub fn monomorphizeFunction(self: *Lowering, fd: *const ast.FnDecl, mangled_name
const result = self.builder.callBuiltin(bid, &.{param0}, ret_ty);
self.builder.ret(result, ret_ty);
} else {
// Unknown bodiless #builtin: the name is not claimed by any
// recognizer (atomics/reflection are handled earlier in call.zig).
// Emitting `ensureTerminator(ret_ty)` here would synthesize a
// silent `constInt(0, ret_ty)` for a non-void return — a silent
// fallback default (issue 0144). Surface the failure loudly.
const span = if (fd.name_span.end != 0) fd.name_span else fd.body.span;
if (self.diagnostics) |d|
d.addFmt(.err, span, "unknown #builtin '{s}'", .{fd.name});
// Lowering has already failed; close the block with a terminator
// so the IR stays well-formed for the rest of the pass.
self.ensureTerminator(ret_ty);
}
self.builder.finalize();