You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
specs/basics/15_loops.t27: sum_to does not compile once a test calls it; the lesson passes only because nothing does #7908
Found while triaging t27b's blocked specs. Part of #6063 (t27b coverage), item C10 of #6488.
What is wrong
specs/basics/15_loops.t27 (lesson 15, upstreamed in #7799) teaches this fn:
pub fn sum_to(n: u8) -> u16 {
var s : u16 = 0;
for i in 0..n {
s = s + i;
}
return s;
}
gen-zig prints the loop as for (0..n) |i|, so i is a usize in Zig, and s = s + i assigns a usize to a u16. Zig refuses that. The lesson's only test checks the constant SUM_BELOW_5, and no test calls sum_to. Zig analyzes a fn lazily, so it never type-checks sum_to, and the file compiles.
Evidence
The t27c lab, zig 0.16.0, t27c test-report:
The lesson as it is: 1/1 pass.
The same file, with assert sum_to(5) == 10; added to its test: BLOCKED, spec.zig:22:15: error: expected type 'u16', found 'usize'.
With s = s + (i as u16); and that assert: 1/1 pass. gen-zig prints @as(u16, @intCast(i)). t27b also passes this version.
t27b (t27b test --blockers, master bbb77f0) refuses the lesson as it is, with type mismatch at line 11 (expected u16, found u64), which is the same error Zig gives. t27b is right not to pass it. The t27b ledger records the file with the reason reference-bug: the reference passes it for the wrong reason.
Proposed fix (for the course owner)
Write the loop body as s = s + (i as u16);.
Add a test that calls sum_to and count_up. Then the lesson's code is checked, not only its constant.
The t27b side needs no change. Once the lesson is fixed, t27b passes it as written.
User Scenarios
Given the lesson specs/basics/15_loops.t27 compiles only because its test does not call sum_to, When a test calls sum_to(5), Then the compiler reports a type mismatch between usize and u16.
Given the loop body is changed to s = s + (i as u16);, When the test calls sum_to(5), Then the file compiles and the assertion passes.
Requirements
FR-001: The loop body in sum_to MUST cast the loop variable to u16 before addition.
FR-002: The lesson's test block MUST include a call to sum_to that exercises the loop.
FR-003: The lesson's test block MUST include a call to count_up that exercises its loop.
Success Criteria
t27c test-report specs/basics/15_loops.t27 exits 0 and reports 2 tests passing.
t27b test --blockers exits 0 and no longer lists specs/basics/15_loops.t27 as a reference-bug.
Fixed as proposed here, by #8914 (issue #8904), merged as 586c6de: the loop body is s = s + (i as u16);, and a second test calls sum_to and count_up. On the t27c lab, t27c test-report gives 2/2 pass with 0 vacuous, and t27b test gives 2 passed. The ledger row is pass.
Activity
Merge master 824c82d into t27b-ptr-eq-7742 (Closes #7742)
Merge master 4627980 into t27b-repeat-local-7909 (Closes #7909)
t27b: a local bound to an array repeat [v; n] and passed as [N]T is t…
t27b: a bench's `_ = e;` is a discard, and ternary_gates' benches typ…
specs/basics/15_loops.t27: sum_to converts its range variable and a t…
gHashTag commentedon Oct 11, 2026
Fixed as proposed here, by #8914 (issue #8904), merged as 586c6de: the loop body is
s = s + (i as u16);, and a second test callssum_toandcount_up. On the t27c lab,t27c test-reportgives 2/2 pass with 0 vacuous, andt27b testgives 2 passed. The ledger row ispass.