authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 18:34:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log8daa8d255b84880de60dc1a86d2f1d4a89463bbc
tree59b91d81929943f420ebf5c5c1af368fe26937fd
parent727b371bbc53b1fcabb6c6899043da3a84195b3c

Sema: fix fn_proto_param LazySrcLoc resolution

to match source code span from merge-base.

5 files changed, 14 insertions(+), 7 deletions(-)

src/Module.zig+9-2
...@@ -2152,8 +2152,15 @@ pub const SrcLoc = struct {...@@ -2152,8 +2152,15 @@ pub const SrcLoc = struct {
2152 while (it.next()) |param| : (i += 1) {2152 while (it.next()) |param| : (i += 1) {
2153 if (i == fn_proto_param.param_index) {2153 if (i == fn_proto_param.param_index) {
2154 if (param.anytype_ellipsis3) |token| return tokenToSpan(tree, token);2154 if (param.anytype_ellipsis3) |token| return tokenToSpan(tree, token);
2155 if (param.name_token) |token| return tokenToSpan(tree, token);2155 const first_token = param.comptime_noalias orelse
2156 return nodeToSpan(tree, param.type_expr);2156 param.name_token orelse
2157 tree.firstToken(param.type_expr);
2158 return tokensToSpan(
2159 tree,
2160 first_token,
2161 tree.lastToken(param.type_expr),
2162 first_token,
2163 );
2157 }2164 }
2158 }2165 }
2159 unreachable;2166 unreachable;
test/cases/compile_errors/array_in_c_exported_function.zig+2-2
...@@ -10,7 +10,7 @@ export fn zig_return_array() [10]u8 {...@@ -10,7 +10,7 @@ export fn zig_return_array() [10]u8 {
10// backend=stage210// backend=stage2
11// target=native11// target=native
12//12//
13// :1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'13// :1:21: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
14// :1:24: note: arrays are not allowed as a parameter type14// :1:21: note: arrays are not allowed as a parameter type
15// :5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'15// :5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
16// :5:30: note: arrays are not allowed as a return type16// :5:30: note: arrays are not allowed as a return type
test/cases/compile_errors/export_function_with_comptime_parameter.zig+1-1
...@@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {...@@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {
6// backend=stage26// backend=stage2
7// target=native7// target=native
8//8//
9// :1:15: error: comptime parameters not allowed in function with calling convention 'C'9// :1:27: error: comptime parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/export_generic_function.zig+1-1
...@@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {...@@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :1:15: error: generic parameters not allowed in function with calling convention 'C'10// :1:20: error: generic parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/extern_function_with_comptime_parameter.zig+1-1
...@@ -19,5 +19,5 @@ comptime {...@@ -19,5 +19,5 @@ comptime {
19// target=native19// target=native
20//20//
21// :5:30: error: comptime parameters not allowed in function with calling convention 'C'21// :5:30: error: comptime parameters not allowed in function with calling convention 'C'
22// :6:30: error: generic parameters not allowed in function with calling convention 'C'22// :6:41: error: generic parameters not allowed in function with calling convention 'C'
23// :1:15: error: comptime parameters not allowed in function with calling convention 'C'23// :1:15: error: comptime parameters not allowed in function with calling convention 'C'