fix(ir): serialize null pointer fields in global aggregates (issue 0081)
A module-global aggregate initializer rejected a `null` literal in a pointer (or optional-pointer) field as "must be initialized by a compile-time constant". `Lowering.constExprValue` had no `.null_literal` arm, so the null leaf returned no constant and the whole aggregate looked non-constant — even though `null` is the compile-time zero pointer (a top-level scalar `p : *s64 = null;` already serialized fine). Add `.null_literal => .null_val` to constExprValue. While here, make the two LLVM constant emitters exhaustive: emitConstAggregate and the top-level init_val switch in emit_llvm.zig previously ended in a silent `else => LLVMConstNull(...)` catch-all (the silent-arm class CLAUDE.md mandates rooting out). They now handle every ConstantValue tag explicitly (.null_val/.zeroinit -> all-zero constant, .undef -> LLVMGetUndef, .func_ref resolved, nested .vtable is a hard @panic tripwire). The reject-loud path for genuinely non-constant fields is preserved. Regression: examples/0138 (array-of-struct null ptr fields, array of all-null pointers, nested struct-in-struct null ptr) and the negative examples/1126 (null ptr field beside a non-const field still errors). Fail-before/pass-after verified.
This commit is contained in:
@@ -1033,6 +1033,10 @@ pub const Lowering = struct {
|
||||
.float_literal => |fl| .{ .float = fl.value },
|
||||
.string_literal => |sl| .{ .string = self.module.types.internString(sl.raw) },
|
||||
.undef_literal => .zeroinit,
|
||||
// A `null` in a pointer (or optional-pointer) field is a
|
||||
// compile-time constant: the zero pointer. Without this arm the
|
||||
// aggregate is wrongly rejected as non-constant (issue 0081).
|
||||
.null_literal => .null_val,
|
||||
.unary_op => |uo| switch (uo.op) {
|
||||
.negate => switch (uo.operand.data) {
|
||||
.int_literal => |il| .{ .int = -il.value },
|
||||
|
||||
Reference in New Issue
Block a user