mirror of
https://github.com/ziglang/zig.git
synced 2026-01-28 10:15:24 +00:00
fix compile crash when leaving out for loop parameter
This commit is contained in:
parent
7aeca9bfed
commit
c64f6f9503
@ -4164,6 +4164,12 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl
|
||||
child_context->parent_loop_node = node;
|
||||
|
||||
AstNode *elem_var_node = node->data.for_expr.elem_node;
|
||||
if (!elem_var_node) {
|
||||
add_node_error(g, node->data.for_expr.body,
|
||||
buf_sprintf("for loop expression missing element parameter"));
|
||||
return g->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
elem_var_node->block_context = child_context;
|
||||
Buf *elem_var_name = elem_var_node->data.symbol_expr.symbol;
|
||||
node->data.for_expr.elem_var = add_local_var(g, elem_var_node, import, child_context, elem_var_name,
|
||||
@ -4180,8 +4186,7 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl
|
||||
g->builtin_types.entry_usize, true, nullptr);
|
||||
}
|
||||
|
||||
AstNode *for_body_node = node->data.for_expr.body;
|
||||
analyze_expression(g, import, child_context, g->builtin_types.entry_void, for_body_node);
|
||||
analyze_expression(g, import, child_context, g->builtin_types.entry_void, node->data.for_expr.body);
|
||||
|
||||
|
||||
return g->builtin_types.entry_void;
|
||||
|
||||
@ -1495,6 +1495,12 @@ pub fn f() {
|
||||
add_compile_fail_case("main function with bogus args type", R"SOURCE(
|
||||
pub fn main(args: [][]bogus) -> %void {}
|
||||
)SOURCE", 1, ".tmp_source.zig:2:23: error: use of undeclared identifier 'bogus'");
|
||||
|
||||
add_compile_fail_case("main function with bogus args type", R"SOURCE(
|
||||
fn foo(blah: []u8) {
|
||||
for (blah) { }
|
||||
}
|
||||
)SOURCE", 1, ".tmp_source.zig:3:16: error: for loop expression missing element parameter");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user