From 2181e0fc279b396710ac9b864e566243d15eaf86 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 8 Aug 2023 15:07:00 +0100 Subject: [PATCH] Make `for init; ; {}` an error without an explicit cond or post --- core/compress/zlib/zlib.odin | 6 +++--- src/parser.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/compress/zlib/zlib.odin b/core/compress/zlib/zlib.odin index 8062c8d3a..f2a39d685 100644 --- a/core/compress/zlib/zlib.odin +++ b/core/compress/zlib/zlib.odin @@ -306,10 +306,10 @@ decode_huffman_slowpath :: proc(z: ^$C, t: ^Huffman_Table) -> (r: u16, err: Erro code := u16(compress.peek_bits_lsb(z,16)) k := int(z_bit_reverse(code, 16)) - s: u8 - #no_bounds_check for s = HUFFMAN_FAST_BITS+1; ; { - if k < t.maxcode[s] { + s: u8 = HUFFMAN_FAST_BITS+1 + for { + #no_bounds_check if k < t.maxcode[s] { break } s += 1 diff --git a/src/parser.cpp b/src/parser.cpp index a2de85d84..695f5c792 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4339,6 +4339,13 @@ gb_internal Ast *parse_for_stmt(AstFile *f) { } cond = convert_stmt_to_expr(f, cond, str_lit("boolean expression")); + if (init != nullptr && + cond == nullptr && + post == nullptr) { + syntax_error(init, "'for init; ; {' without an explicit condition nor post statement is not allowed, please prefer something like 'for init; true; /**/{'"); + } + + return ast_for_stmt(f, token, init, cond, post, body); }