Browse Source

Make `for init; ; {}` an error without an explicit cond or post

gingerBill 2 years ago
parent
commit
2181e0fc27
2 changed files with 10 additions and 3 deletions
  1. 3 3
      core/compress/zlib/zlib.odin
  2. 7 0
      src/parser.cpp

+ 3 - 3
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

+ 7 - 0
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);
 }