| ... | ... | @@ -1344,6 +1344,16 @@ static AstNode *create_ast_type_node(CodeGen *g, ImportTableEntry *import, TypeT |
| 1344 | 1344 | return node; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | static AstNode *create_ast_void_node(CodeGen *g, ImportTableEntry *import, AstNode *source_node) { |
| 1348 | AstNode *node = create_ast_node(g, import, NodeTypeContainerInitExpr); |
| 1349 | node->data.container_init_expr.kind = ContainerInitKindArray; |
| 1350 | node->data.container_init_expr.type = create_ast_type_node(g, import, g->builtin_types.entry_void); |
| 1351 | node->line = source_node->line; |
| 1352 | node->column = source_node->column; |
| 1353 | normalize_parent_ptrs(node); |
| 1354 | return node; |
| 1355 | } |
| 1356 | |
| 1347 | 1357 | static TypeTableEntry *create_and_analyze_cast_node(CodeGen *g, ImportTableEntry *import, |
| 1348 | 1358 | BlockContext *context, TypeTableEntry *cast_to_type, AstNode *node) |
| 1349 | 1359 | { |
| ... | ... | @@ -3596,25 +3606,17 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import, |
| 3596 | 3606 | return g->builtin_types.entry_invalid; |
| 3597 | 3607 | } |
| 3598 | 3608 | |
| 3609 | if (!node->data.return_expr.expr) { |
| 3610 | node->data.return_expr.expr = create_ast_void_node(g, import, node); |
| 3611 | normalize_parent_ptrs(node); |
| 3612 | } |
| 3613 | |
| 3599 | 3614 | if (node->data.return_expr.kind != ReturnKindUnconditional) { |
| 3600 | 3615 | zig_panic("TODO analyze_return_expr conditional"); |
| 3601 | 3616 | } |
| 3602 | 3617 | |
| 3603 | 3618 | TypeTableEntry *expected_return_type = get_return_type(context); |
| 3604 | | TypeTableEntry *actual_return_type; |
| 3605 | | if (node->data.return_expr.expr) { |
| 3606 | | actual_return_type = analyze_expression(g, import, context, expected_return_type, node->data.return_expr.expr); |
| 3607 | | } else { |
| 3608 | | actual_return_type = g->builtin_types.entry_void; |
| 3609 | | } |
| 3610 | | |
| 3611 | | if (actual_return_type->id == TypeTableEntryIdUnreachable) { |
| 3612 | | // "return exit(0)" should just be "exit(0)". |
| 3613 | | add_node_error(g, node, buf_sprintf("returning is unreachable")); |
| 3614 | | actual_return_type = g->builtin_types.entry_invalid; |
| 3615 | | } |
| 3616 | | |
| 3617 | | resolve_type_compatibility(g, import, context, node, expected_return_type, actual_return_type); |
| 3619 | analyze_expression(g, import, context, expected_return_type, node->data.return_expr.expr); |
| 3618 | 3620 | |
| 3619 | 3621 | return g->builtin_types.entry_unreachable; |
| 3620 | 3622 | } |