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) {...@@ -4238,7 +4238,8 @@ AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) {
4238 return nullptr;4238 return nullptr;
4239}4239}
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;
4242 ZigType *fn_type = fn_table_entry->type_entry;4243 ZigType *fn_type = fn_table_entry->type_entry;
4243 assert(!fn_type->data.fn.is_generic);4244 assert(!fn_type->data.fn.is_generic);
4244 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;4245 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) {...@@ -4257,8 +4258,11 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4257 }4258 }
42584259
4259 ZigType *param_type = param_info->type;4260 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;
4262 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {4266 if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
4263 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));4267 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
4264 }4268 }
...@@ -4273,6 +4277,8 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4273,6 +4277,8 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4273 fn_table_entry->variable_list.append(var);4277 fn_table_entry->variable_list.append(var);
4274 }4278 }
4275 }4279 }
4280
4281 return ErrorNone;
4276}4282}
42774283
4278bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {4284bool 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) {...@@ -4596,7 +4602,10 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
4596 if (!fn_table_entry->child_scope)4602 if (!fn_table_entry->child_scope)
4597 fn_table_entry->child_scope = &fn_table_entry->fndef_scope->base;4603 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
4601 ZigType *fn_type = fn_table_entry->type_entry;4610 ZigType *fn_type = fn_table_entry->type_entry;
4602 assert(!fn_type->data.fn.is_generic);4611 assert(!fn_type->data.fn.is_generic);
test/compile_errors.zig+12
...@@ -2,6 +2,18 @@ const tests = @import("tests.zig");...@@ -2,6 +2,18 @@ const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub 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
5 cases.add(17 cases.add(
6 "using an unknown len ptr type instead of array",18 "using an unknown len ptr type instead of array",
7 \\const resolutions = [*][*]const u8{19 \\const resolutions = [*][*]const u8{