| author | |
| committer | |
| log | f2a6a1756bd3d3e284410c001ee997c4d12a260b |
| tree | 0b932c7e86e287ffa15708389bfc90a69fe43384 |
| parent | 552e8095ae62654d0ba7dffbc8e0e1dfb6499c9d |
2 files changed, 17 insertions(+), 1 deletions(-)
src/Sema.zig+5-1| ... | ... | @@ -3924,7 +3924,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 3924 | 3924 | const object_ty = sema.typeOf(object); |
| 3925 | 3925 | // Each arg could be an indexable, or a range, in which case the length |
| 3926 | 3926 | // is passed directly as an integer. |
| 3927 | const arg_len = if (object_ty.zigTypeTag() == .Int) object else l: { | |
| 3927 | const is_int = switch (object_ty.zigTypeTag()) { | |
| 3928 | .Int, .ComptimeInt => true, | |
| 3929 | else => false, | |
| 3930 | }; | |
| 3931 | const arg_len = if (is_int) object else l: { | |
| 3928 | 3932 | try checkIndexable(sema, block, src, object_ty); |
| 3929 | 3933 | if (!object_ty.indexableHasLen()) continue; |
| 3930 | 3934 |
test/behavior/for.zig+12| ... | ... | @@ -249,3 +249,15 @@ test "for loop with else branch" { |
| 249 | 249 | try expect(q == 4); |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | ||
| 253 | test "count over fixed range" { | |
| 254 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | |
| 255 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 256 | ||
| 257 | var sum: usize = 0; | |
| 258 | for (0..6) |i| { | |
| 259 | sum += i; | |
| 260 | } | |
| 261 | ||
| 262 | try expect(sum == 15); | |
| 263 | } |