authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-25 16:40:43+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-26 12:14:59+03:00
log28478a4bac0bfb80d373cc156dfff034459bb0b9
tree6995ec52d7b2faa81259adfbb71d6d3e1eb89f57
parent20ea44ef107828d76692e610e1ca62ee231fb4a9

Module: improve handling of errors in `@call` arguments


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

src/Module.zig+10-3
......@@ -5939,10 +5939,11 @@ pub fn argSrc(
59395939 call_node_offset: i32,
59405940 gpa: Allocator,
59415941 decl: *Decl,
5942 arg_i: usize,
5942 start_arg_i: usize,
59435943 bound_arg_src: ?LazySrcLoc,
59445944) LazySrcLoc {
5945 if (arg_i == 0 and bound_arg_src != null) return bound_arg_src.?;
5945 if (start_arg_i == 0 and bound_arg_src != null) return bound_arg_src.?;
5946 const arg_i = start_arg_i - @boolToInt(bound_arg_src != null);
59465947 @setCold(true);
59475948 const tree = decl.getFileScope().getTree(gpa) catch |err| {
59485949 // In this case we emit a warning + a less precise source location.
......@@ -5957,6 +5958,12 @@ pub fn argSrc(
59575958 const full = switch (node_tags[node]) {
59585959 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(&args, node),
59595960 .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node),
5961 .builtin_call => {
5962 const node_datas = tree.nodes.items(.data);
5963 const call_args_node = tree.extra_data[node_datas[node].rhs - 1];
5964 const call_args_offset = decl.nodeIndexToRelative(call_args_node);
5965 return initSrc(call_args_offset, gpa, decl, arg_i);
5966 },
59605967 else => unreachable,
59615968 };
59625969 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full.ast.params[arg_i]));
......@@ -5989,7 +5996,7 @@ pub fn initSrc(
59895996 .struct_init_dot_two, .struct_init_dot_two_comma => tree.structInitDotTwo(&buf, node).ast.fields,
59905997 .struct_init_dot, .struct_init_dot_comma => tree.structInitDot(node).ast.fields,
59915998 .struct_init, .struct_init_comma => tree.structInit(node).ast.fields,
5992 else => unreachable,
5999 else => return LazySrcLoc.nodeOffset(init_node_offset),
59936000 };
59946001 switch (node_tags[node]) {
59956002 .array_init_one,
test/cases/compile_errors/error_in_call_builtin_args.zig created+15
......@@ -0,0 +1,15 @@
1fn foo(_: u32, _: u32) void {}
2pub export fn entry() void {
3 @call(.{}, foo, .{ 12, 12.34 });
4}
5pub export fn entry1() void {
6 const args = .{ 12, 12.34 };
7 @call(.{}, foo, args);
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :3:28: error: fractional component prevents float value '12.34' from coercion to type 'u32'
15// :7:21: error: fractional component prevents float value '12.34' from coercion to type 'u32'