Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4548,6 +4548,9 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
// This argument is a range.
const range_start = try sema.resolveInst(zir_arg_pair[0]);
const range_end = try sema.resolveInst(zir_arg_pair[1]);
if (try sema.resolveDefinedValue(block, arg_src, range_start)) |start| {
if (try sema.valuesEqual(start, .zero_usize, .usize)) break :l range_end;
}
break :l try sema.analyzeArithmetic(block, .sub, range_end, range_start, arg_src, arg_src, arg_src, true);
};
const arg_len = try sema.coerce(block, .usize, arg_len_uncoerced, arg_src);
Expand Down Expand Up @@ -4611,12 +4614,18 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.

// Now for the runtime checks.
if (any_runtime and block.wantSafety()) {
var ok: Air.Inst.Ref = .none;
for (runtime_arg_lens, 0..) |arg_len, i| {
if (arg_len == .none) continue;
if (i == len_idx) continue;
const ok = try block.addBinOp(.cmp_eq, len, arg_len);
try sema.addSafetyCheck(block, src, ok, .for_len_mismatch);
const eq = try block.addBinOp(.cmp_eq, len, arg_len);
ok = if (ok != .none)
try block.addBinOp(.bool_and, ok, eq)
else
eq;
}
if (ok != .none)
try sema.addSafetyCheck(block, src, ok, .for_len_mismatch);
}

return len;
Expand Down