authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-13 01:00:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-13 01:00:50-05:00
log4551489b924fad262eb3343b68fc4c0e18ed6a97
tree2e789eb23598215ebe5f56d23fc0ae83fa88ce35
parent32ea6f54e5f05c4173828c4f4c8ab9965a929120

typecheck the panic function


1 files changed, 7 insertions(+), 3 deletions(-)

src/analyze.cpp+7-3
...@@ -2584,17 +2584,16 @@ static bool scope_is_root_decls(Scope *scope) {...@@ -2584,17 +2584,16 @@ static bool scope_is_root_decls(Scope *scope) {
25842584
2585static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) {2585static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) {
2586 add_node_error(g, proto_node,2586 add_node_error(g, proto_node,
2587 buf_sprintf("expected 'fn([]const u8) -> unreachable', found '%s'",2587 buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) -> unreachable', found '%s'",
2588 buf_ptr(&fn_type->name)));2588 buf_ptr(&fn_type->name)));
2589}2589}
25902590
2591static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {2591static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
2592 return; // TODO
2593 AstNode *proto_node = panic_fn->proto_node;2592 AstNode *proto_node = panic_fn->proto_node;
2594 assert(proto_node->type == NodeTypeFnProto);2593 assert(proto_node->type == NodeTypeFnProto);
2595 TypeTableEntry *fn_type = panic_fn->type_entry;2594 TypeTableEntry *fn_type = panic_fn->type_entry;
2596 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;2595 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
2597 if (fn_type_id->param_count != 1) {2596 if (fn_type_id->param_count != 2) {
2598 return wrong_panic_prototype(g, proto_node, fn_type);2597 return wrong_panic_prototype(g, proto_node, fn_type);
2599 }2598 }
2600 TypeTableEntry *const_u8_ptr = get_pointer_to_type(g, g->builtin_types.entry_u8, true);2599 TypeTableEntry *const_u8_ptr = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
...@@ -2603,6 +2602,11 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {...@@ -2603,6 +2602,11 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
2603 return wrong_panic_prototype(g, proto_node, fn_type);2602 return wrong_panic_prototype(g, proto_node, fn_type);
2604 }2603 }
26052604
2605 TypeTableEntry *nullable_ptr_to_stack_trace_type = get_maybe_type(g, get_ptr_to_stack_trace_type(g));
2606 if (fn_type_id->param_info[1].type != nullable_ptr_to_stack_trace_type) {
2607 return wrong_panic_prototype(g, proto_node, fn_type);
2608 }
2609
2606 TypeTableEntry *actual_return_type = fn_type_id->return_type;2610 TypeTableEntry *actual_return_type = fn_type_id->return_type;
2607 if (actual_return_type != g->builtin_types.entry_unreachable) {2611 if (actual_return_type != g->builtin_types.entry_unreachable) {
2608 return wrong_panic_prototype(g, proto_node, fn_type);2612 return wrong_panic_prototype(g, proto_node, fn_type);