diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-01-13 01:00:50 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-01-13 01:00:50 -0500 |
| commit | 4551489b924fad262eb3343b68fc4c0e18ed6a97 (patch) | |
| tree | 2e789eb23598215ebe5f56d23fc0ae83fa88ce35 /src/analyze.cpp | |
| parent | 32ea6f54e5f05c4173828c4f4c8ab9965a929120 (diff) | |
| download | zig-4551489b924fad262eb3343b68fc4c0e18ed6a97.tar.gz zig-4551489b924fad262eb3343b68fc4c0e18ed6a97.zip | |
typecheck the panic function
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 61d86b5eb2..b52cb019d3 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2584,17 +2584,16 @@ static bool scope_is_root_decls(Scope *scope) { static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) { add_node_error(g, proto_node, - buf_sprintf("expected 'fn([]const u8) -> unreachable', found '%s'", + buf_sprintf("expected 'fn([]const u8, ?&builtin.StackTrace) -> unreachable', found '%s'", buf_ptr(&fn_type->name))); } static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) { - return; // TODO AstNode *proto_node = panic_fn->proto_node; assert(proto_node->type == NodeTypeFnProto); TypeTableEntry *fn_type = panic_fn->type_entry; FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; - if (fn_type_id->param_count != 1) { + if (fn_type_id->param_count != 2) { return wrong_panic_prototype(g, proto_node, fn_type); } 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) { return wrong_panic_prototype(g, proto_node, fn_type); } + TypeTableEntry *nullable_ptr_to_stack_trace_type = get_maybe_type(g, get_ptr_to_stack_trace_type(g)); + if (fn_type_id->param_info[1].type != nullable_ptr_to_stack_trace_type) { + return wrong_panic_prototype(g, proto_node, fn_type); + } + TypeTableEntry *actual_return_type = fn_type_id->return_type; if (actual_return_type != g->builtin_types.entry_unreachable) { return wrong_panic_prototype(g, proto_node, fn_type); |
