fix(ir): precise oversized-dim diagnostic on the alias path (0083)
The stateless alias-registration array-dim path collapsed foldDimU32's distinct .too_large / .below_min outcomes into null, so an oversized type alias (Big :: [5000000000]s64) emitted the FALSE 'an array dimension is not a compile-time integer constant' message while the direct form correctly reported 'array dimension 5000000000 does not fit in u32'. Add program_index.reportDimError as the single source of dim-error wording (the stateful path now emits through it too) and type_bridge.foldArrayDim to surface the DimU32 reason at the alias-registration site. An oversized/negative alias dim now routes to reportDimError for the same precise message as the direct form; a genuinely non-const alias dim keeps the alias-specific message. Regression: examples/1131-diagnostics-array-dim-oversized-u32-alias.sx
This commit is contained in:
@@ -2,6 +2,7 @@ const std = @import("std");
|
||||
const ast = @import("../ast.zig");
|
||||
const types = @import("types.zig");
|
||||
const inst = @import("inst.zig");
|
||||
const errors = @import("../errors.zig");
|
||||
|
||||
const Node = ast.Node;
|
||||
const TypeId = types.TypeId;
|
||||
@@ -147,6 +148,24 @@ pub fn foldDimU32(node: *const Node, ctx: anytype, min: u32) DimU32 {
|
||||
return .{ .ok = @intCast(v) };
|
||||
}
|
||||
|
||||
/// THE single source of array-dimension diagnostic wording. Both array-dim
|
||||
/// resolvers — the stateful body-lowering path (`Lowering.resolveArrayLen`) and
|
||||
/// the stateless registration-time path (the alias-registration site, via
|
||||
/// `type_bridge.foldArrayDim`) — emit through here, so an oversized / negative /
|
||||
/// non-const dimension reports the SAME message regardless of whether it was
|
||||
/// written directly (`a : [N]T`) or via a type alias (`Arr :: [N]T`). Folding
|
||||
/// the wording into one place is the diagnostic-accuracy half of the issue-0083
|
||||
/// unify-or-diverge story: `foldDimU32` is the single fold, this is the single
|
||||
/// message map. Only call with a non-`.ok` result (the `.ok` arm is a no-op).
|
||||
pub fn reportDimError(diag: *errors.DiagnosticList, span: ?ast.Span, result: DimU32) void {
|
||||
switch (result) {
|
||||
.ok => {},
|
||||
.below_min => |v| diag.addFmt(.err, span, "array dimension must be non-negative, got {}", .{v}),
|
||||
.too_large => |v| diag.addFmt(.err, span, "array dimension {} does not fit in u32", .{v}),
|
||||
.not_const => diag.addFmt(.err, span, "array dimension must be a compile-time integer constant", .{}),
|
||||
}
|
||||
}
|
||||
|
||||
pub const GlobalInfo = struct { id: inst.GlobalId, ty: TypeId };
|
||||
|
||||
/// Single lowering access point for declaration-name / import / visibility
|
||||
|
||||
Reference in New Issue
Block a user