mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
Sema: fix error location on comptime arg to typed generic param
Closes #14505
This commit is contained in:
parent
f3bb1957fa
commit
490addde27
13
src/Sema.zig
13
src/Sema.zig
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user