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

Closes #14505
This commit is contained in:
Veikka Tuominen 2023-02-01 20:50:43 +02:00
parent f3bb1957fa
commit 490addde27
2 changed files with 33 additions and 1 deletions

View File

@ -9015,7 +9015,18 @@ fn zirParam(
if (is_comptime and sema.preallocated_new_func != null) {
// We have a comptime value for this parameter so it should be elided from the
// function type of the function instruction in this block.
const coerced_arg = try sema.coerce(block, param_ty, arg, src);
const coerced_arg = sema.coerce(block, param_ty, arg, .unneeded) catch |err| switch (err) {
error.NeededSourceLocation => {
// We are instantiating a generic function and a comptime arg
// cannot be coerced to the param type, but since we don't
// have the callee source location return `GenericPoison`
// so that the instantiation is failed and the coercion
// is handled by comptime call logic instead.
assert(sema.is_generic_instantiation);
return error.GenericPoison;
},
else => return err,
};
sema.inst_map.putAssumeCapacity(inst, coerced_arg);
return;
}

View File

@ -0,0 +1,21 @@
const std = @import("std");
const MyStruct = struct {
a: i32,
b: i32,
pub fn getA(self: *List) i32 {
return self.items(.c);
}
};
const List = std.MultiArrayList(MyStruct);
pub export fn entry() void {
var list = List{};
_ = MyStruct.getA(&list);
}
// error
// backend=stage2
// target=native
//
// :7:28: error: no field named 'c' in enum 'meta.FieldEnum(tmp.MyStruct)'
// :?:?: note: enum declared here