| ... | @@ -1698,10 +1698,11 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: | ... | @@ -1698,10 +1698,11 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options: |
| 1698 | var r: T = undefined; | 1698 | var r: T = undefined; |
| 1699 | var i: usize = 0; | 1699 | var i: usize = 0; |
| 1700 | errdefer { | 1700 | errdefer { |
| 1701 | while (true) : (i -= 1) { | 1701 | // Without the r.len check `r[i]` is not allowed |
| | 1702 | if (r.len > 0) while (true) : (i -= 1) { |
| 1702 | parseFree(arrayInfo.child, r[i], options); | 1703 | parseFree(arrayInfo.child, r[i], options); |
| 1703 | if (i == 0) break; | 1704 | if (i == 0) break; |
| 1704 | } | 1705 | }; |
| 1705 | } | 1706 | } |
| 1706 | while (i < r.len) : (i += 1) { | 1707 | while (i < r.len) : (i += 1) { |
| 1707 | r[i] = try parse(arrayInfo.child, tokens, options); | 1708 | r[i] = try parse(arrayInfo.child, tokens, options); |
| ... | @@ -1854,6 +1855,7 @@ test "parse" { | ... | @@ -1854,6 +1855,7 @@ test "parse" { |
| 1854 | | 1855 | |
| 1855 | try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{})); | 1856 | try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("\"foo\""), ParseOptions{})); |
| 1856 | try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{})); | 1857 | try testing.expectEqual(@as([3]u8, "foo".*), try parse([3]u8, &TokenStream.init("[102, 111, 111]"), ParseOptions{})); |
| | 1858 | try testing.expectEqual(@as([0]u8, undefined), try parse([0]u8, &TokenStream.init("[]"), ParseOptions{})); |
| 1857 | } | 1859 | } |
| 1858 | | 1860 | |
| 1859 | test "parse into enum" { | 1861 | test "parse into enum" { |