authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-11-04 10:11:33+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-11-04 20:33:40+01:00
log61825062aadd68e6cd2e864c717b3a8ce482258d
tree676f66143eae2742792f6701072a790ae9744f6a
parentc8b6e552991136e3a45095007ae4c3594be02ef9

Correctly process errors for invalid types in fn call

Fixes #3544

2 files changed, 24 insertions(+), 3 deletions(-)

src/analyze.cpp+12-3
......@@ -4238,7 +4238,8 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) {
42384238 return nullptr;
42394239}
42404240
4241static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4241static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4242 Error err;
42424243 ZigType *fn_type = fn_table_entry->type_entry;
42434244 assert(!fn_type->data.fn.is_generic);
42444245 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
......@@ -4257,8 +4258,11 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
42574258 }
42584259
42594260 ZigType *param_type = param_info->type;
4260 bool is_noalias = param_info->is_noalias;
4261 if ((err = type_resolve(g, param_type, ResolveStatusSizeKnown))) {
4262 return err;
4263 }
42614264
4265 bool is_noalias = param_info->is_noalias;
42624266 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
42634267 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
42644268 }
......@@ -4273,6 +4277,8 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
42734277 fn_table_entry->variable_list.append(var);
42744278 }
42754279 }
4280
4281 return ErrorNone;
42764282}
42774283
42784284bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {
......@@ -4596,7 +4602,10 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
45964602 if (!fn_table_entry->child_scope)
45974603 fn_table_entry->child_scope = &fn_table_entry->fndef_scope->base;
45984604
4599 define_local_param_variables(g, fn_table_entry);
4605 if (define_local_param_variables(g, fn_table_entry) != ErrorNone) {
4606 fn_table_entry->anal_state = FnAnalStateInvalid;
4607 return;
4608 }
46004609
46014610 ZigType *fn_type = fn_table_entry->type_entry;
46024611 assert(!fn_type->data.fn.is_generic);
test/compile_errors.zig+12
......@@ -2,6 +2,18 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "using invalid types in function call raises an error",
7 \\const MenuEffect = enum {};
8 \\fn func(effect: MenuEffect) void {}
9 \\export fn entry() void {
10 \\ func(MenuEffect.ThisDoesNotExist);
11 \\}
12 ,
13 "tmp.zig:1:20: error: enums must have 1 or more fields",
14 "tmp.zig:4:20: note: referenced here",
15 );
16
517 cases.add(
618 "using an unknown len ptr type instead of array",
719 \\const resolutions = [*][*]const u8{