diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-25 16:40:43 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-26 12:14:59 +0300 |
| commit | 28478a4bac0bfb80d373cc156dfff034459bb0b9 (patch) | |
| tree | 6995ec52d7b2faa81259adfbb71d6d3e1eb89f57 | |
| parent | 20ea44ef107828d76692e610e1ca62ee231fb4a9 (diff) | |
| download | zig-28478a4bac0bfb80d373cc156dfff034459bb0b9.tar.gz zig-28478a4bac0bfb80d373cc156dfff034459bb0b9.zip | |
Module: improve handling of errors in `@call` arguments
| -rw-r--r-- | src/Module.zig | 13 | ||||
| -rw-r--r-- | test/cases/compile_errors/error_in_call_builtin_args.zig | 15 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/Module.zig b/src/Module.zig index 1e684f6ea1..cfb6c5f32a 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -5939,10 +5939,11 @@ pub fn argSrc( call_node_offset: i32, gpa: Allocator, decl: *Decl, - arg_i: usize, + start_arg_i: usize, bound_arg_src: ?LazySrcLoc, ) LazySrcLoc { - if (arg_i == 0 and bound_arg_src != null) return bound_arg_src.?; + if (start_arg_i == 0 and bound_arg_src != null) return bound_arg_src.?; + const arg_i = start_arg_i - @boolToInt(bound_arg_src != null); @setCold(true); const tree = decl.getFileScope().getTree(gpa) catch |err| { // In this case we emit a warning + a less precise source location. @@ -5957,6 +5958,12 @@ pub fn argSrc( const full = switch (node_tags[node]) { .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(&args, node), .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node), + .builtin_call => { + const node_datas = tree.nodes.items(.data); + const call_args_node = tree.extra_data[node_datas[node].rhs - 1]; + const call_args_offset = decl.nodeIndexToRelative(call_args_node); + return initSrc(call_args_offset, gpa, decl, arg_i); + }, else => unreachable, }; return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full.ast.params[arg_i])); @@ -5989,7 +5996,7 @@ pub fn initSrc( .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(&buf, node).ast.fields, .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node).ast.fields, .struct_init, .struct_init_comma => tree.structInit(node).ast.fields, - else => unreachable, + else => return LazySrcLoc.nodeOffset(init_node_offset), }; switch (node_tags[node]) { .array_init_one, diff --git a/test/cases/compile_errors/error_in_call_builtin_args.zig b/test/cases/compile_errors/error_in_call_builtin_args.zig new file mode 100644 index 0000000000..ca46f7fe77 --- /dev/null +++ b/test/cases/compile_errors/error_in_call_builtin_args.zig @@ -0,0 +1,15 @@ +fn foo(_: u32, _: u32) void {} +pub export fn entry() void { + @call(.{}, foo, .{ 12, 12.34 }); +} +pub export fn entry1() void { + const args = .{ 12, 12.34 }; + @call(.{}, foo, args); +} + +// error +// backend=stage2 +// target=native +// +// :3:28: error: fractional component prevents float value '12.34' from coercion to type 'u32' +// :7:21: error: fractional component prevents float value '12.34' from coercion to type 'u32' |
