cli: check inferred array elements before AIR

This commit is contained in:
dev committed 2026-10-08 09:26:33 +03:00
1 parent cfbe01a16f
commit 1bbfed24a8
40 files changed
+337 -9

No files matched your search

+15 -1
View File
@@ -762,6 +762,19 @@ const Lowerer = struct {
// ------------------------------------------------------------ functions
fn arrayElement(l: *Lowerer, span: Span, ty: Ty, repeated: bool) Error!void {
if (ty.isBorrow()) return l.invalid(.invalid_literal, span, "an array element cannot be a borrow", &.{});
const t = try l.airType(ty);
if (!verifier_types.allowedPosition(std.meta.activeTag(t), .member, true)) return l.fail("E7005", span, "type constructor not allowed in this position", &.{
.{ .name = "position", .value = "member" },
.{ .name = "type_constructor", .value = @tagName(t) },
});
if (repeated and !verifier_types.isCopy(l.property_module.?, t)) return l.fail("E7005", span, "an array repetition requires Copy content", &.{
.{ .name = "constraint", .value = "Copy" },
.{ .name = "type_constructor", .value = "array" },
});
}
fn function(l: *Lowerer, f: ast.FnDecl) Error!FnOut {
l.blocks = .empty;
l.bindings = .empty;
@@ -1576,6 +1589,7 @@ const Lowerer = struct {
var names: std.ArrayList(u8) = .empty;
for (xs, 0..) |x, i| {
const v = try l.consuming(x, ty);
try l.arrayElement(x.span, v.ty, false);
if (ty) |t| try l.checkTy(x.span, v.ty, t) else ty = v.ty;
try names.appendSlice(l.arena, try l.fmt("{s}%{s}", .{ if (i == 0) "" else ", ", v.name }));
}
@@ -1586,7 +1600,7 @@ const Lowerer = struct {
if (x.len == 0 or x.len > (@as(u64, 1) << 32)) return l.fail("E7005", e.span, "array length must be between 1 and 2^32", &.{});
const want_elem: ?Ty = if (want) |w| (if (w == .array) w.array.elem else null) else null;
const v = try l.expr(x.e.*, want_elem);
if (v.ty.isBorrow()) return l.invalid(.invalid_literal, x.e.span, "an array element cannot be a borrow", &.{});
try l.arrayElement(x.e.span, v.ty, true);
const at = try l.arrayOf(v.ty, x.len);
return l.def("arr", at, try l.fmt("array.splat {s} %{s}", .{ l.tyText(at), v.name }), e.span);
},