Sema: use the correct decl for generic argument source locations

Closes #16746
This commit is contained in:
Jacob Young
2023-08-09 09:26:16 -04:00
parent 9630379a8e
commit 736df27663
2 changed files with 54 additions and 19 deletions
+36
View File
@@ -183,4 +183,40 @@ pub fn addCases(ctx: *Cases) !void {
":1:1: note: invalid byte: '\\xff'",
});
}
{
const case = ctx.obj("imported generic method call with invalid param", .{});
case.addError(
\\pub const import = @import("import.zig");
\\
\\export fn callComptimeBoolFunctionWithRuntimeBool(x: bool) void {
\\ import.comptimeBoolFunction(x);
\\}
\\
\\export fn callComptimeAnytypeFunctionWithRuntimeBool(x: bool) void {
\\ import.comptimeAnytypeFunction(x);
\\}
\\
\\export fn callAnytypeFunctionWithRuntimeComptimeOnlyType(x: u32) void {
\\ const S = struct { x: u32, y: type };
\\ import.anytypeFunction(S{ .x = x, .y = u32 });
\\}
, &[_][]const u8{
":4:33: error: runtime-known argument passed to comptime parameter",
":1:38: note: declared comptime here",
":8:36: error: runtime-known argument passed to comptime parameter",
":2:41: note: declared comptime here",
":13:29: error: runtime-known argument passed to comptime-only type parameter",
":3:24: note: declared here",
":12:35: note: struct requires comptime because of this field",
":12:35: note: types are not available at runtime",
});
case.addSourceFile("import.zig",
\\pub fn comptimeBoolFunction(comptime _: bool) void {}
\\pub fn comptimeAnytypeFunction(comptime _: anytype) void {}
\\pub fn anytypeFunction(_: anytype) void {}
);
}
}