authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-02-01 20:50:43+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-02-01 20:50:43+02:00
log490addde278001694d554a9a9fe2eb8235831143
tree93c966416c0a767200ce82e199661690cd9f76c9
parentf3bb1957fa7f317873584cfc0ea8e3fd59283ec2

Sema: fix error location on comptime arg to typed generic param

Closes #14505

2 files changed, 33 insertions(+), 1 deletions(-)

src/Sema.zig+12-1
...@@ -9015,7 +9015,18 @@ fn zirParam(...@@ -9015,7 +9015,18 @@ fn zirParam(
9015 if (is_comptime and sema.preallocated_new_func != null) {9015 if (is_comptime and sema.preallocated_new_func != null) {
9016 // We have a comptime value for this parameter so it should be elided from the9016 // We have a comptime value for this parameter so it should be elided from the
9017 // function type of the function instruction in this block.9017 // function type of the function instruction in this block.
9018 const coerced_arg = try sema.coerce(block, param_ty, arg, src);9018 const coerced_arg = sema.coerce(block, param_ty, arg, .unneeded) catch |err| switch (err) {
9019 error.NeededSourceLocation => {
9020 // We are instantiating a generic function and a comptime arg
9021 // cannot be coerced to the param type, but since we don't
9022 // have the callee source location return `GenericPoison`
9023 // so that the instantiation is failed and the coercion
9024 // is handled by comptime call logic instead.
9025 assert(sema.is_generic_instantiation);
9026 return error.GenericPoison;
9027 },
9028 else => return err,
9029 };
9019 sema.inst_map.putAssumeCapacity(inst, coerced_arg);9030 sema.inst_map.putAssumeCapacity(inst, coerced_arg);
9020 return;9031 return;
9021 }9032 }
test/cases/compile_errors/comptime_arg_to_generic_fn_callee_error.zig created+21
...@@ -0,0 +1,21 @@
1const std = @import("std");
2const MyStruct = struct {
3 a: i32,
4 b: i32,
5
6 pub fn getA(self: *List) i32 {
7 return self.items(.c);
8 }
9};
10const List = std.MultiArrayList(MyStruct);
11pub export fn entry() void {
12 var list = List{};
13 _ = MyStruct.getA(&list);
14}
15
16// error
17// backend=stage2
18// target=native
19//
20// :7:28: error: no field named 'c' in enum 'meta.FieldEnum(tmp.MyStruct)'
21// :?:?: note: enum declared here