Sema: fix fn_proto_param LazySrcLoc resolution

to match source code span from merge-base.
This commit is contained in:
Andrew Kelley 2023-07-18 18:34:14 -07:00
parent 727b371bbc
commit 8daa8d255b
5 changed files with 14 additions and 7 deletions

View File

@ -2152,8 +2152,15 @@ pub const SrcLoc = struct {
while (it.next()) |param| : (i += 1) {
if (i == fn_proto_param.param_index) {
if (param.anytype_ellipsis3) |token| return tokenToSpan(tree, token);
if (param.name_token) |token| return tokenToSpan(tree, token);
return nodeToSpan(tree, param.type_expr);
const first_token = param.comptime_noalias orelse
param.name_token orelse
tree.firstToken(param.type_expr);
return tokensToSpan(
tree,
first_token,
tree.lastToken(param.type_expr),
first_token,
);
}
}
unreachable;

View File

@ -10,7 +10,7 @@ export fn zig_return_array() [10]u8 {
// backend=stage2
// target=native
//
// :1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
// :1:24: note: arrays are not allowed as a parameter type
// :1:21: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
// :1:21: note: arrays are not allowed as a parameter type
// :5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
// :5:30: note: arrays are not allowed as a return type

View File

@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {
// backend=stage2
// target=native
//
// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
// :1:27: error: comptime parameters not allowed in function with calling convention 'C'

View File

@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {
// backend=stage2
// target=native
//
// :1:15: error: generic parameters not allowed in function with calling convention 'C'
// :1:20: error: generic parameters not allowed in function with calling convention 'C'

View File

@ -19,5 +19,5 @@ comptime {
// target=native
//
// :5:30: error: comptime parameters not allowed in function with calling convention 'C'
// :6:30: error: generic parameters not allowed in function with calling convention 'C'
// :6:41: error: generic parameters not allowed in function with calling convention 'C'
// :1:15: error: comptime parameters not allowed in function with calling convention 'C'