authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2023-07-04 10:34:31-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-19 15:15:05+03:00
logee4ced96833470f9432e6a5dc5b31534457280c0
tree8d35dc654895f029e23ce710367b839814ed5cd9
parent3e79315d19c7dfe5f9b90185d8030209ef8dd829

write function types consistently with a space before `fn` keyword

Currently, the compiler (like @typeName) writes it `fn(...) Type` but zig fmt writes it `fn (...) Type` (notice the space after `fn`). This inconsistency is now resolved and function types are consistently written the zig fmt way. Before this there were more `fn (...) Type` occurrences than `fn(...) Type` already.

43 files changed, 91 insertions(+), 91 deletions(-)

lib/std/atomic/Atomic.zig+1-1
...@@ -21,7 +21,7 @@ pub fn Atomic(comptime T: type) type {...@@ -21,7 +21,7 @@ pub fn Atomic(comptime T: type) type {
21 /// ```21 /// ```
22 /// const RefCount = struct {22 /// const RefCount = struct {
23 /// count: Atomic(usize),23 /// count: Atomic(usize),
24 /// dropFn: *const fn(*RefCount) void,24 /// dropFn: *const fn (*RefCount) void,
25 ///25 ///
26 /// fn ref(self: *RefCount) void {26 /// fn ref(self: *RefCount) void {
27 /// _ = self.count.fetchAdd(1, .Monotonic); // no ordering necessary, just updating a counter27 /// _ = self.count.fetchAdd(1, .Monotonic); // no ordering necessary, just updating a counter
lib/std/enums.zig+4-4
...@@ -1269,10 +1269,10 @@ pub fn ensureIndexer(comptime T: type) void {...@@ -1269,10 +1269,10 @@ pub fn ensureIndexer(comptime T: type) void {
1269 if (@TypeOf(T.Key) != type) @compileError("Indexer.Key must be a type.");1269 if (@TypeOf(T.Key) != type) @compileError("Indexer.Key must be a type.");
1270 if (!@hasDecl(T, "count")) @compileError("Indexer must have decl count: usize.");1270 if (!@hasDecl(T, "count")) @compileError("Indexer must have decl count: usize.");
1271 if (@TypeOf(T.count) != usize) @compileError("Indexer.count must be a usize.");1271 if (@TypeOf(T.count) != usize) @compileError("Indexer.count must be a usize.");
1272 if (!@hasDecl(T, "indexOf")) @compileError("Indexer.indexOf must be a fn(Key)usize.");1272 if (!@hasDecl(T, "indexOf")) @compileError("Indexer.indexOf must be a fn (Key) usize.");
1273 if (@TypeOf(T.indexOf) != fn (T.Key) usize) @compileError("Indexer must have decl indexOf: fn(Key)usize.");1273 if (@TypeOf(T.indexOf) != fn (T.Key) usize) @compileError("Indexer must have decl indexOf: fn (Key) usize.");
1274 if (!@hasDecl(T, "keyForIndex")) @compileError("Indexer must have decl keyForIndex: fn(usize)Key.");1274 if (!@hasDecl(T, "keyForIndex")) @compileError("Indexer must have decl keyForIndex: fn (usize) Key.");
1275 if (@TypeOf(T.keyForIndex) != fn (usize) T.Key) @compileError("Indexer.keyForIndex must be a fn(usize)Key.");1275 if (@TypeOf(T.keyForIndex) != fn (usize) T.Key) @compileError("Indexer.keyForIndex must be a fn (usize) Key.");
1276 }1276 }
1277}1277}
12781278
lib/std/fmt.zig+2-2
...@@ -2255,11 +2255,11 @@ test "pointer" {...@@ -2255,11 +2255,11 @@ test "pointer" {
2255 const FnPtr = *align(1) const fn () void;2255 const FnPtr = *align(1) const fn () void;
2256 {2256 {
2257 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));2257 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
2258 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});2258 try expectFmt("pointer: fn () void@deadbeef\n", "pointer: {}\n", .{value});
2259 }2259 }
2260 {2260 {
2261 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));2261 const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
2262 try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});2262 try expectFmt("pointer: fn () void@deadbeef\n", "pointer: {}\n", .{value});
2263 }2263 }
2264}2264}
22652265
lib/std/meta.zig+3-3
...@@ -969,9 +969,9 @@ test "std.meta.Float" {...@@ -969,9 +969,9 @@ test "std.meta.Float" {
969/// correspond to the argument types.969/// correspond to the argument types.
970///970///
971/// Examples:971/// Examples:
972/// - `ArgsTuple(fn() void)` ⇒ `tuple { }`972/// - `ArgsTuple(fn () void)` ⇒ `tuple { }`
973/// - `ArgsTuple(fn(a: u32) u32)` ⇒ `tuple { u32 }`973/// - `ArgsTuple(fn (a: u32) u32)` ⇒ `tuple { u32 }`
974/// - `ArgsTuple(fn(a: u32, b: f16) noreturn)` ⇒ `tuple { u32, f16 }`974/// - `ArgsTuple(fn (a: u32, b: f16) noreturn)` ⇒ `tuple { u32, f16 }`
975pub fn ArgsTuple(comptime Function: type) type {975pub fn ArgsTuple(comptime Function: type) type {
976 const info = @typeInfo(Function);976 const info = @typeInfo(Function);
977 if (info != .Fn)977 if (info != .Fn)
lib/std/treap.zig+1-1
...@@ -7,7 +7,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {...@@ -7,7 +7,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
7 return struct {7 return struct {
8 const Self = @This();8 const Self = @This();
99
10 // Allow for compareFn to be fn(anytype, anytype) anytype10 // Allow for compareFn to be fn (anytype, anytype) anytype
11 // which allows the convenient use of std.math.order.11 // which allows the convenient use of std.math.order.
12 fn compare(a: Key, b: Key) Order {12 fn compare(a: Key, b: Key) Order {
13 return compareFn(a, b);13 return compareFn(a, b);
lib/std/zig/Ast.zig+4-4
...@@ -3255,23 +3255,23 @@ pub const Node = struct {...@@ -3255,23 +3255,23 @@ pub const Node = struct {
3255 @"break",3255 @"break",
3256 /// `return lhs`. lhs can be omitted. rhs is unused.3256 /// `return lhs`. lhs can be omitted. rhs is unused.
3257 @"return",3257 @"return",
3258 /// `fn(a: lhs) rhs`. lhs can be omitted.3258 /// `fn (a: lhs) rhs`. lhs can be omitted.
3259 /// anytype and ... parameters are omitted from the AST tree.3259 /// anytype and ... parameters are omitted from the AST tree.
3260 /// main_token is the `fn` keyword.3260 /// main_token is the `fn` keyword.
3261 /// extern function declarations use this tag.3261 /// extern function declarations use this tag.
3262 fn_proto_simple,3262 fn_proto_simple,
3263 /// `fn(a: b, c: d) rhs`. `sub_range_list[lhs]`.3263 /// `fn (a: b, c: d) rhs`. `sub_range_list[lhs]`.
3264 /// anytype and ... parameters are omitted from the AST tree.3264 /// anytype and ... parameters are omitted from the AST tree.
3265 /// main_token is the `fn` keyword.3265 /// main_token is the `fn` keyword.
3266 /// extern function declarations use this tag.3266 /// extern function declarations use this tag.
3267 fn_proto_multi,3267 fn_proto_multi,
3268 /// `fn(a: b) rhs addrspace(e) linksection(f) callconv(g)`. `FnProtoOne[lhs]`.3268 /// `fn (a: b) rhs addrspace(e) linksection(f) callconv(g)`. `FnProtoOne[lhs]`.
3269 /// zero or one parameters.3269 /// zero or one parameters.
3270 /// anytype and ... parameters are omitted from the AST tree.3270 /// anytype and ... parameters are omitted from the AST tree.
3271 /// main_token is the `fn` keyword.3271 /// main_token is the `fn` keyword.
3272 /// extern function declarations use this tag.3272 /// extern function declarations use this tag.
3273 fn_proto_one,3273 fn_proto_one,
3274 /// `fn(a: b, c: d) rhs addrspace(e) linksection(f) callconv(g)`. `FnProto[lhs]`.3274 /// `fn (a: b, c: d) rhs addrspace(e) linksection(f) callconv(g)`. `FnProto[lhs]`.
3275 /// anytype and ... parameters are omitted from the AST tree.3275 /// anytype and ... parameters are omitted from the AST tree.
3276 /// main_token is the `fn` keyword.3276 /// main_token is the `fn` keyword.
3277 /// extern function declarations use this tag.3277 /// extern function declarations use this tag.
lib/std/zig/parser_test.zig+2-2
...@@ -5251,8 +5251,8 @@ test "zig fmt: make single-line if no trailing comma, fmt: off" {...@@ -5251,8 +5251,8 @@ test "zig fmt: make single-line if no trailing comma, fmt: off" {
5251 \\ }5251 \\ }
5252 \\}5252 \\}
5253 \\5253 \\
5254 \\const fn_no_comma = fn(i32, i32)void;5254 \\const fn_no_comma = fn (i32, i32) void;
5255 \\const fn_trailing_comma = fn(i32, i32,)void;5255 \\const fn_trailing_comma = fn (i32, i32,) void;
5256 \\5256 \\
5257 \\fn fn_calls() void {5257 \\fn fn_calls() void {
5258 \\ fn add(x: i32, y: i32,) i32 { x + y };5258 \\ fn add(x: i32, y: i32,) i32 { x + y };
src/Sema.zig+1-1
...@@ -6722,7 +6722,7 @@ fn zirCall(...@@ -6722,7 +6722,7 @@ fn zirCall(
6722 {6722 {
6723 const return_ty = sema.typeOf(call_inst);6723 const return_ty = sema.typeOf(call_inst);
6724 if (modifier != .always_tail and return_ty.isNoReturn(mod))6724 if (modifier != .always_tail and return_ty.isNoReturn(mod))
6725 return call_inst; // call to "fn(...) noreturn", don't pop6725 return call_inst; // call to "fn (...) noreturn", don't pop
67266726
6727 // TODO: we don't fix up the error trace for always_tail correctly, we should be doing it6727 // TODO: we don't fix up the error trace for always_tail correctly, we should be doing it
6728 // *before* the recursive call. This will be a bit tricky to do and probably requires6728 // *before* the recursive call. This will be a bit tricky to do and probably requires
src/type.zig+1-1
...@@ -364,7 +364,7 @@ pub const Type = struct {...@@ -364,7 +364,7 @@ pub const Type = struct {
364 if (fn_info.is_noinline) {364 if (fn_info.is_noinline) {
365 try writer.writeAll("noinline ");365 try writer.writeAll("noinline ");
366 }366 }
367 try writer.writeAll("fn(");367 try writer.writeAll("fn (");
368 const param_types = fn_info.param_types.get(&mod.intern_pool);368 const param_types = fn_info.param_types.get(&mod.intern_pool);
369 for (param_types, 0..) |param_ty, i| {369 for (param_types, 0..) |param_ty, i| {
370 if (i != 0) try writer.writeAll(", ");370 if (i != 0) try writer.writeAll(", ");
test/behavior/cast.zig+1-1
...@@ -1194,7 +1194,7 @@ test "implicit ptr to *anyopaque" {...@@ -1194,7 +1194,7 @@ test "implicit ptr to *anyopaque" {
1194 try expect(c.* == 1);1194 try expect(c.* == 1);
1195}1195}
11961196
1197test "return null from fn() anyerror!?&T" {1197test "return null from fn () anyerror!?&T" {
1198 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;1198 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1199 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1199 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1200 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1200 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
test/behavior/typename.zig+16-16
...@@ -73,18 +73,18 @@ test "basic" {...@@ -73,18 +73,18 @@ test "basic" {
73 try expectEqualStrings("*usize", @typeName(*usize));73 try expectEqualStrings("*usize", @typeName(*usize));
74 try expectEqualStrings("[]u8", @typeName([]u8));74 try expectEqualStrings("[]u8", @typeName([]u8));
7575
76 try expectEqualStrings("fn() void", @typeName(fn () void));76 try expectEqualStrings("fn () void", @typeName(fn () void));
77 try expectEqualStrings("fn(u32) void", @typeName(fn (u32) void));77 try expectEqualStrings("fn (u32) void", @typeName(fn (u32) void));
78 try expectEqualStrings("fn(u32) void", @typeName(fn (a: u32) void));78 try expectEqualStrings("fn (u32) void", @typeName(fn (a: u32) void));
7979
80 try expectEqualStrings("fn(comptime u32) void", @typeName(fn (comptime u32) void));80 try expectEqualStrings("fn (comptime u32) void", @typeName(fn (comptime u32) void));
81 try expectEqualStrings("fn(noalias []u8) void", @typeName(fn (noalias []u8) void));81 try expectEqualStrings("fn (noalias []u8) void", @typeName(fn (noalias []u8) void));
8282
83 try expectEqualStrings("fn() align(32) void", @typeName(fn () align(32) void));83 try expectEqualStrings("fn () align(32) void", @typeName(fn () align(32) void));
84 try expectEqualStrings("fn() callconv(.C) void", @typeName(fn () callconv(.C) void));84 try expectEqualStrings("fn () callconv(.C) void", @typeName(fn () callconv(.C) void));
85 try expectEqualStrings("fn() align(32) callconv(.C) void", @typeName(fn () align(32) callconv(.C) void));85 try expectEqualStrings("fn () align(32) callconv(.C) void", @typeName(fn () align(32) callconv(.C) void));
86 try expectEqualStrings("fn(...) align(32) callconv(.C) void", @typeName(fn (...) align(32) callconv(.C) void));86 try expectEqualStrings("fn (...) align(32) callconv(.C) void", @typeName(fn (...) align(32) callconv(.C) void));
87 try expectEqualStrings("fn(u32, ...) align(32) callconv(.C) void", @typeName(fn (u32, ...) align(32) callconv(.C) void));87 try expectEqualStrings("fn (u32, ...) align(32) callconv(.C) void", @typeName(fn (u32, ...) align(32) callconv(.C) void));
88}88}
8989
90test "top level decl" {90test "top level decl" {
...@@ -108,17 +108,17 @@ test "top level decl" {...@@ -108,17 +108,17 @@ test "top level decl" {
108108
109 // regular fn, without error109 // regular fn, without error
110 try expectEqualStrings(110 try expectEqualStrings(
111 "fn() void",111 "fn () void",
112 @typeName(@TypeOf(regular)),112 @typeName(@TypeOf(regular)),
113 );113 );
114 // regular fn inside struct, with error114 // regular fn inside struct, with error
115 try expectEqualStrings(115 try expectEqualStrings(
116 "fn() @typeInfo(@typeInfo(@TypeOf(behavior.typename.B.doTest)).Fn.return_type.?).ErrorUnion.error_set!void",116 "fn () @typeInfo(@typeInfo(@TypeOf(behavior.typename.B.doTest)).Fn.return_type.?).ErrorUnion.error_set!void",
117 @typeName(@TypeOf(B.doTest)),117 @typeName(@TypeOf(B.doTest)),
118 );118 );
119 // generic fn119 // generic fn
120 try expectEqualStrings(120 try expectEqualStrings(
121 "fn(comptime type) type",121 "fn (comptime type) type",
122 @typeName(@TypeOf(TypeFromFn)),122 @typeName(@TypeOf(TypeFromFn)),
123 );123 );
124}124}
...@@ -234,7 +234,7 @@ test "comptime parameters not converted to anytype in function type" {...@@ -234,7 +234,7 @@ test "comptime parameters not converted to anytype in function type" {
234 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;234 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
235235
236 const T = fn (fn (type) void, void) void;236 const T = fn (fn (type) void, void) void;
237 try expectEqualStrings("fn(comptime fn(comptime type) void, void) void", @typeName(T));237 try expectEqualStrings("fn (comptime fn (comptime type) void, void) void", @typeName(T));
238}238}
239239
240test "anon name strategy used in sub expression" {240test "anon name strategy used in sub expression" {
test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig+1-1
...@@ -16,4 +16,4 @@ pub export fn entry() void {...@@ -16,4 +16,4 @@ pub export fn entry() void {
16// :8:12: error: variable of type 'tmp.S1' must be const or comptime16// :8:12: error: variable of type 'tmp.S1' must be const or comptime
17// :2:8: note: struct requires comptime because of this field17// :2:8: note: struct requires comptime because of this field
18// :5:8: note: struct requires comptime because of this field18// :5:8: note: struct requires comptime because of this field
19// :5:8: note: use '*const fn() void' for a function pointer type19// :5:8: note: use '*const fn () void' for a function pointer type
test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig+1-1
...@@ -8,5 +8,5 @@ inline fn b() void {}...@@ -8,5 +8,5 @@ inline fn b() void {}
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :2:9: error: variable of type '*const fn() callconv(.Inline) void' must be const or comptime11// :2:9: error: variable of type '*const fn () callconv(.Inline) void' must be const or comptime
12// :2:9: note: function has inline calling convention12// :2:9: note: function has inline calling convention
test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig+1-1
...@@ -9,4 +9,4 @@ fn afunc() void {}...@@ -9,4 +9,4 @@ fn afunc() void {}
9// backend=stage19// backend=stage1
10// target=native10// target=native
11//11//
12// tmp.zig:4:32: error: expected async function, found 'fn() void'12// tmp.zig:4:32: error: expected async function, found 'fn () void'
test/cases/compile_errors/call_optional_function.zig+2-2
...@@ -11,7 +11,7 @@ pub export fn entry2() void {...@@ -11,7 +11,7 @@ pub export fn entry2() void {
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :3:9: error: cannot call optional type '?fn() void'14// :3:9: error: cannot call optional type '?fn () void'
15// :3:9: note: consider using '.?', 'orelse' or 'if'15// :3:9: note: consider using '.?', 'orelse' or 'if'
16// :7:9: error: cannot call optional type '?*const fn() void'16// :7:9: error: cannot call optional type '?*const fn () void'
17// :7:9: note: consider using '.?', 'orelse' or 'if'17// :7:9: note: consider using '.?', 'orelse' or 'if'
test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig+4-4
...@@ -17,10 +17,10 @@ export fn entry2() void {...@@ -17,10 +17,10 @@ export fn entry2() void {
17// backend=stage217// backend=stage2
18// target=native18// target=native
19//19//
20// :6:9: error: expected type '?*const fn(i8) void', found '?*const fn(u64) void'20// :6:9: error: expected type '?*const fn (i8) void', found '?*const fn (u64) void'
21// :6:9: note: pointer type child 'fn(u64) void' cannot cast into pointer type child 'fn(i8) void'21// :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void'
22// :6:9: note: parameter 0 'u64' cannot cast into 'i8'22// :6:9: note: parameter 0 'u64' cannot cast into 'i8'
23// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values23// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
24// :13:9: error: expected type '?*const fn(u63) void', found '?*const fn(u64) void'24// :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
25// :13:9: note: pointer type child 'fn(u64) void' cannot cast into pointer type child 'fn(u63) void'25// :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
26// :13:9: note: parameter 0 'u64' cannot cast into 'u63'26// :13:9: note: parameter 0 'u64' cannot cast into 'u63'
test/cases/compile_errors/comptime_param_coersion.zig+2-2
...@@ -14,7 +14,7 @@ fn bar(comptime _: i32, _: i32) void {}...@@ -14,7 +14,7 @@ fn bar(comptime _: i32, _: i32) void {}
14// backend=stage214// backend=stage2
15// target=native15// target=native
16//16//
17// :3:9: error: expected type 'fn(comptime i32, comptime i32) void', found 'fn(comptime i32, i32) void'17// :3:9: error: expected type 'fn (comptime i32, comptime i32) void', found 'fn (comptime i32, i32) void'
18// :3:9: note: non-comptime parameter 1 cannot cast into a comptime parameter18// :3:9: note: non-comptime parameter 1 cannot cast into a comptime parameter
19// :7:9: error: expected type 'fn(i32, i32) void', found 'fn(comptime i32, comptime i32) void'19// :7:9: error: expected type 'fn (i32, i32) void', found 'fn (comptime i32, comptime i32) void'
20// :7:9: note: generic function cannot cast into a non-generic function20// :7:9: note: generic function cannot cast into a non-generic function
test/cases/compile_errors/comptime_parameter_not_declared_as_such.zig+1-1
...@@ -20,6 +20,6 @@ pub export fn entry1() void {...@@ -20,6 +20,6 @@ pub export fn entry1() void {
20// backend=stage220// backend=stage2
21// target=native21// target=native
22//22//
23// :3:6: error: parameter of type '*const fn(anytype) void' must be declared comptime23// :3:6: error: parameter of type '*const fn (anytype) void' must be declared comptime
24// :3:6: note: function is generic24// :3:6: note: function is generic
25// :10:34: error: parameter of type 'comptime_int' must be declared comptime25// :10:34: error: parameter of type 'comptime_int' must be declared comptime
test/cases/compile_errors/condition_comptime_reason_explained.zig+2-2
...@@ -40,11 +40,11 @@ pub export fn entry2() void {...@@ -40,11 +40,11 @@ pub export fn entry2() void {
40// :8:9: note: condition in comptime branch must be comptime-known40// :8:9: note: condition in comptime branch must be comptime-known
41// :7:13: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'41// :7:13: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
42// :2:12: note: struct requires comptime because of this field42// :2:12: note: struct requires comptime because of this field
43// :2:12: note: use '*const fn() void' for a function pointer type43// :2:12: note: use '*const fn () void' for a function pointer type
44// :19:15: note: called from here44// :19:15: note: called from here
45// :22:13: error: unable to resolve comptime value45// :22:13: error: unable to resolve comptime value
46// :22:13: note: condition in comptime switch must be comptime-known46// :22:13: note: condition in comptime switch must be comptime-known
47// :21:17: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'47// :21:17: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
48// :2:12: note: struct requires comptime because of this field48// :2:12: note: struct requires comptime because of this field
49// :2:12: note: use '*const fn() void' for a function pointer type49// :2:12: note: use '*const fn () void' for a function pointer type
50// :32:19: note: called from here50// :32:19: note: called from here
test/cases/compile_errors/dereference_anyopaque.zig+6-6
...@@ -46,9 +46,9 @@ pub export fn entry() void {...@@ -46,9 +46,9 @@ pub export fn entry() void {
46//46//
47// :11:22: error: comparison of 'void' with null47// :11:22: error: comparison of 'void' with null
48// :25:51: error: cannot load opaque type 'anyopaque'48// :25:51: error: cannot load opaque type 'anyopaque'
49// :25:51: error: values of type 'fn(*anyopaque, usize, u8, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known49// :25:51: error: values of type 'fn (*anyopaque, usize, u8, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
50// :25:51: note: use '*const fn(*anyopaque, usize, u8, usize) ?[*]u8' for a function pointer type50// :25:51: note: use '*const fn (*anyopaque, usize, u8, usize) ?[*]u8' for a function pointer type
51// :25:51: error: values of type 'fn(*anyopaque, []u8, u8, usize, usize) bool' must be comptime-known, but operand value is runtime-known51// :25:51: error: values of type 'fn (*anyopaque, []u8, u8, usize, usize) bool' must be comptime-known, but operand value is runtime-known
52// :25:51: note: use '*const fn(*anyopaque, []u8, u8, usize, usize) bool' for a function pointer type52// :25:51: note: use '*const fn (*anyopaque, []u8, u8, usize, usize) bool' for a function pointer type
53// :25:51: error: values of type 'fn(*anyopaque, []u8, u8, usize) void' must be comptime-known, but operand value is runtime-known53// :25:51: error: values of type 'fn (*anyopaque, []u8, u8, usize) void' must be comptime-known, but operand value is runtime-known
54// :25:51: note: use '*const fn(*anyopaque, []u8, u8, usize) void' for a function pointer type54// :25:51: note: use '*const fn (*anyopaque, []u8, u8, usize) void' for a function pointer type
test/cases/compile_errors/error_note_for_function_parameter_incompatibility.zig+2-2
...@@ -12,6 +12,6 @@ export fn entry() void {...@@ -12,6 +12,6 @@ export fn entry() void {
12// backend=stage212// backend=stage2
13// target=native13// target=native
14//14//
15// :8:18: error: expected type '*const fn(i32) void', found '*const fn(bool) void'15// :8:18: error: expected type '*const fn (i32) void', found '*const fn (bool) void'
16// :8:18: note: pointer type child 'fn(bool) void' cannot cast into pointer type child 'fn(i32) void'16// :8:18: note: pointer type child 'fn (bool) void' cannot cast into pointer type child 'fn (i32) void'
17// :8:18: note: parameter 0 'bool' cannot cast into 'i32'17// :8:18: note: parameter 0 'bool' cannot cast into 'i32'
test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig+1-1
...@@ -20,4 +20,4 @@ pub export fn entry() void {...@@ -20,4 +20,4 @@ pub export fn entry() void {
20// :12:13: note: argument to function being called at comptime must be comptime-known20// :12:13: note: argument to function being called at comptime must be comptime-known
21// :7:25: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'21// :7:25: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
22// :2:12: note: struct requires comptime because of this field22// :2:12: note: struct requires comptime because of this field
23// :2:12: note: use '*const fn() void' for a function pointer type23// :2:12: note: use '*const fn () void' for a function pointer type
test/cases/compile_errors/extern_function_pointer_mismatch.zig+1-1
...@@ -17,5 +17,5 @@ export fn entry() usize {...@@ -17,5 +17,5 @@ export fn entry() usize {
17// backend=stage217// backend=stage2
18// target=native18// target=native
19//19//
20// :1:38: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'20// :1:38: error: expected type 'fn (i32) i32', found 'fn (i32) callconv(.C) i32'
21// :1:38: note: calling convention 'C' cannot cast into calling convention 'Unspecified'21// :1:38: note: calling convention 'C' cannot cast into calling convention 'Unspecified'
test/cases/compile_errors/file_level_struct_invalid_field_type.zig+1-1
...@@ -14,4 +14,4 @@ comptime {...@@ -14,4 +14,4 @@ comptime {
14// backend=stage214// backend=stage2
15// target=native15// target=native
16//16//
17// :7:15: error: expected type 'type', found 'fn() type'17// :7:15: error: expected type 'type', found 'fn () type'
test/cases/compile_errors/function_type_coercion.zig+3-3
...@@ -13,9 +13,9 @@ export fn wrong_return_type() void {...@@ -13,9 +13,9 @@ export fn wrong_return_type() void {
13// backend=stage2,llvm13// backend=stage2,llvm
14// target=native14// target=native
15//15//
16// :3:25: error: expected type 'fn() void', found 'fn(i32) void'16// :3:25: error: expected type 'fn () void', found 'fn (i32) void'
17// :3:25: note: function with 1 parameters cannot cast into a function with 0 parameters17// :3:25: note: function with 1 parameters cannot cast into a function with 0 parameters
18// :6:28: error: expected type 'fn(f32) void', found 'fn(i32) void'18// :6:28: error: expected type 'fn (f32) void', found 'fn (i32) void'
19// :6:28: note: parameter 0 'i32' cannot cast into 'f32'19// :6:28: note: parameter 0 'i32' cannot cast into 'f32'
20// :9:24: error: expected type 'fn() i32', found 'fn(i32) void'20// :9:24: error: expected type 'fn () i32', found 'fn (i32) void'
21// :9:24: note: return type 'void' cannot cast into return type 'i32'21// :9:24: note: return type 'void' cannot cast into return type 'i32'
test/cases/compile_errors/invalid_array_elem_ty.zig+1-1
...@@ -9,4 +9,4 @@ pub export fn entry() void {...@@ -9,4 +9,4 @@ pub export fn entry() void {
9// target=native9// target=native
10// backend=stage210// backend=stage2
11//11//
12// :5:12: error: expected type 'type', found 'fn() type'12// :5:12: error: expected type 'type', found 'fn () type'
test/cases/compile_errors/invalid_comparison_for_function_pointers.zig+1-1
...@@ -9,4 +9,4 @@ export fn entry() usize {...@@ -9,4 +9,4 @@ export fn entry() usize {
9// backend=stage29// backend=stage2
10// target=native10// target=native
11//11//
12// :2:21: error: operator > not allowed for type 'fn() void'12// :2:21: error: operator > not allowed for type 'fn () void'
test/cases/compile_errors/invalid_tail_call.zig+1-1
...@@ -9,4 +9,4 @@ pub export fn entry() void {...@@ -9,4 +9,4 @@ pub export fn entry() void {
9// backend=llvm9// backend=llvm
10// target=native10// target=native
11//11//
12// :5:5: error: unable to perform tail call: type of function being called 'fn(usize) void' does not match type of calling function 'fn() callconv(.C) void'12// :5:5: error: unable to perform tail call: type of function being called 'fn (usize) void' does not match type of calling function 'fn () callconv(.C) void'
test/cases/compile_errors/nested_generic_function_param_type_mismatch.zig+2-2
...@@ -19,6 +19,6 @@ pub export fn entry() void {...@@ -19,6 +19,6 @@ pub export fn entry() void {
19// backend=llvm19// backend=llvm
20// target=native20// target=native
21//21//
22// :15:28: error: expected type '*const fn(comptime type, u8, u8) u32', found '*const fn(void, u8, u8) u32'22// :15:28: error: expected type '*const fn (comptime type, u8, u8) u32', found '*const fn (void, u8, u8) u32'
23// :15:28: note: pointer type child 'fn(void, u8, u8) u32' cannot cast into pointer type child 'fn(comptime type, u8, u8) u32'23// :15:28: note: pointer type child 'fn (void, u8, u8) u32' cannot cast into pointer type child 'fn (comptime type, u8, u8) u32'
24// :15:28: note: non-generic function cannot cast into a generic function24// :15:28: note: non-generic function cannot cast into a generic function
test/cases/compile_errors/noalias_param_coersion.zig+2-2
...@@ -14,7 +14,7 @@ fn bar(noalias _: *i32, _: *i32) void {}...@@ -14,7 +14,7 @@ fn bar(noalias _: *i32, _: *i32) void {}
14// backend=stage214// backend=stage2
15// target=native15// target=native
16//16//
17// :3:9: error: expected type 'fn(noalias *i32, noalias *i32) void', found 'fn(noalias *i32, *i32) void'17// :3:9: error: expected type 'fn (noalias *i32, noalias *i32) void', found 'fn (noalias *i32, *i32) void'
18// :3:9: note: regular parameter 1 cannot cast into a noalias parameter18// :3:9: note: regular parameter 1 cannot cast into a noalias parameter
19// :7:9: error: expected type 'fn(*i32, *i32) void', found 'fn(noalias *i32, noalias *i32) void'19// :7:9: error: expected type 'fn (*i32, *i32) void', found 'fn (noalias *i32, noalias *i32) void'
20// :7:9: note: noalias parameter 0 cannot cast into a regular parameter20// :7:9: note: noalias parameter 0 cannot cast into a regular parameter
test/cases/compile_errors/non_comptime_param_in_comptime_function.zig+1-1
...@@ -31,6 +31,6 @@ export fn entry2() void {...@@ -31,6 +31,6 @@ export fn entry2() void {
31// :1:6: note: param 'val' is required to be comptime31// :1:6: note: param 'val' is required to be comptime
32// :11:16: error: function with comptime-only return type 'tmp.S' requires all parameters to be comptime32// :11:16: error: function with comptime-only return type 'tmp.S' requires all parameters to be comptime
33// :9:10: note: struct requires comptime because of this field33// :9:10: note: struct requires comptime because of this field
34// :9:10: note: use '*const fn() void' for a function pointer type34// :9:10: note: use '*const fn () void' for a function pointer type
35// :11:8: note: param is required to be comptime35// :11:8: note: param is required to be comptime
36// :18:29: error: return type 'comptime_int' not allowed in function with calling convention 'C'36// :18:29: error: return type 'comptime_int' not allowed in function with calling convention 'C'
test/cases/compile_errors/old_fn_ptr_in_extern_context.zig+2-2
...@@ -12,9 +12,9 @@ comptime {...@@ -12,9 +12,9 @@ comptime {
12// backend=stage212// backend=stage2
13// target=native13// target=native
14//14//
15// :2:8: error: extern structs cannot contain fields of type 'fn() callconv(.C) void'15// :2:8: error: extern structs cannot contain fields of type 'fn () callconv(.C) void'
16// :2:8: note: type has no guaranteed in-memory representation16// :2:8: note: type has no guaranteed in-memory representation
17// :2:8: note: use '*const ' to make a function pointer type17// :2:8: note: use '*const ' to make a function pointer type
18// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn() callconv(.C) void'18// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn () callconv(.C) void'
19// :8:13: note: type has no guaranteed in-memory representation19// :8:13: note: type has no guaranteed in-memory representation
20// :8:13: note: use '*const ' to make a function pointer type20// :8:13: note: use '*const ' to make a function pointer type
test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig+1-1
...@@ -84,7 +84,7 @@ export fn entry12() void {...@@ -84,7 +84,7 @@ export fn entry12() void {
84// :59:18: note: union declared here84// :59:18: note: union declared here
85// :28:12: error: packed structs cannot contain fields of type '?anyerror'85// :28:12: error: packed structs cannot contain fields of type '?anyerror'
86// :28:12: note: type has no guaranteed in-memory representation86// :28:12: note: type has no guaranteed in-memory representation
87// :38:12: error: packed structs cannot contain fields of type 'fn() void'87// :38:12: error: packed structs cannot contain fields of type 'fn () void'
88// :38:12: note: type has no guaranteed in-memory representation88// :38:12: note: type has no guaranteed in-memory representation
89// :38:12: note: use '*const ' to make a function pointer type89// :38:12: note: use '*const ' to make a function pointer type
90// :65:31: error: packed structs cannot contain fields of type '[]u8'90// :65:31: error: packed structs cannot contain fields of type '[]u8'
test/cases/compile_errors/passing_an_under-aligned_function_pointer.zig+1-1
...@@ -12,5 +12,5 @@ fn alignedSmall() align(4) i32 {...@@ -12,5 +12,5 @@ fn alignedSmall() align(4) i32 {
12// backend=stage212// backend=stage2
13// target=x86_64-linux13// target=x86_64-linux
14//14//
15// :2:35: error: expected type '*const fn() align(8) i32', found '*const fn() align(4) i32'15// :2:35: error: expected type '*const fn () align(8) i32', found '*const fn () align(4) i32'
16// :2:35: note: pointer alignment '4' cannot cast into pointer alignment '8'16// :2:35: note: pointer alignment '4' cannot cast into pointer alignment '8'
test/cases/compile_errors/runtime_indexing_comptime_array.zig+6-6
...@@ -24,9 +24,9 @@ pub export fn entry3() void {...@@ -24,9 +24,9 @@ pub export fn entry3() void {
24// target=native24// target=native
25// backend=stage225// backend=stage2
26//26//
27// :7:10: error: values of type '[2]fn() void' must be comptime-known, but index value is runtime-known27// :7:10: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
28// :7:10: note: use '*const fn() void' for a function pointer type28// :7:10: note: use '*const fn () void' for a function pointer type
29// :15:18: error: values of type '[2]fn() void' must be comptime-known, but index value is runtime-known29// :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
30// :15:17: note: use '*const fn() void' for a function pointer type30// :15:17: note: use '*const fn () void' for a function pointer type
31// :21:19: error: values of type '[2]fn() void' must be comptime-known, but index value is runtime-known31// :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
32// :21:18: note: use '*const fn() void' for a function pointer type32// :21:18: note: use '*const fn () void' for a function pointer type
test/cases/compile_errors/self_referential_struct_requires_comptime.zig+1-1
...@@ -13,5 +13,5 @@ pub export fn entry() void {...@@ -13,5 +13,5 @@ pub export fn entry() void {
13//13//
14// :6:12: error: variable of type 'tmp.S' must be const or comptime14// :6:12: error: variable of type 'tmp.S' must be const or comptime
15// :2:8: note: struct requires comptime because of this field15// :2:8: note: struct requires comptime because of this field
16// :2:8: note: use '*const fn() void' for a function pointer type16// :2:8: note: use '*const fn () void' for a function pointer type
17// :3:8: note: struct requires comptime because of this field17// :3:8: note: struct requires comptime because of this field
test/cases/compile_errors/self_referential_union_requires_comptime.zig+1-1
...@@ -13,5 +13,5 @@ pub export fn entry() void {...@@ -13,5 +13,5 @@ pub export fn entry() void {
13//13//
14// :6:12: error: variable of type 'tmp.U' must be const or comptime14// :6:12: error: variable of type 'tmp.U' must be const or comptime
15// :2:8: note: union requires comptime because of this field15// :2:8: note: union requires comptime because of this field
16// :2:8: note: use '*const fn() void' for a function pointer type16// :2:8: note: use '*const fn () void' for a function pointer type
17// :3:8: note: union requires comptime because of this field17// :3:8: note: union requires comptime because of this field
test/cases/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig+1-1
...@@ -8,4 +8,4 @@ export fn entry() void {...@@ -8,4 +8,4 @@ export fn entry() void {
8// backend=stage18// backend=stage1
9// target=native9// target=native
10//10//
11// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime11// tmp.zig:1:9: error: parameter of type 'fn (anytype) anytype' must be declared comptime
test/cases/compile_errors/type_checking_function_pointers.zig+2-2
...@@ -12,6 +12,6 @@ export fn entry() void {...@@ -12,6 +12,6 @@ export fn entry() void {
12// backend=stage212// backend=stage2
13// target=native13// target=native
14//14//
15// :8:7: error: expected type '*const fn(*const u8) void', found '*const fn(u8) void'15// :8:7: error: expected type '*const fn (*const u8) void', found '*const fn (u8) void'
16// :8:7: note: pointer type child 'fn(u8) void' cannot cast into pointer type child 'fn(*const u8) void'16// :8:7: note: pointer type child 'fn (u8) void' cannot cast into pointer type child 'fn (*const u8) void'
17// :8:7: note: parameter 0 'u8' cannot cast into '*const u8'17// :8:7: note: parameter 0 'u8' cannot cast into '*const u8'
test/cases/compile_errors/type_mismatch_in_C_prototype_with_varargs.zig+1-1
...@@ -10,6 +10,6 @@ export fn main() void {...@@ -10,6 +10,6 @@ export fn main() void {
10// backend=stage210// backend=stage2
11// target=native11// target=native
12//12//
13// :5:22: error: expected type '?fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'13// :5:22: error: expected type '?fn ([*c]u8, ...) callconv(.C) void', found 'fn ([*:0]u8, ...) callconv(.C) void'
14// :5:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8'14// :5:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8'
15// :5:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'15// :5:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'
test/cases/compile_errors/wrong_function_type.zig+1-1
...@@ -16,5 +16,5 @@ export fn entry() usize {...@@ -16,5 +16,5 @@ export fn entry() usize {
16// backend=stage216// backend=stage2
17// target=native17// target=native
18//18//
19// :1:28: error: expected type 'fn() void', found 'fn() i32'19// :1:28: error: expected type 'fn () void', found 'fn () i32'
20// :1:28: note: return type 'i32' cannot cast into return type 'void'20// :1:28: note: return type 'i32' cannot cast into return type 'void'
test/cases/compile_log.0.zig+1-1
...@@ -17,6 +17,6 @@ fn x() void {}...@@ -17,6 +17,6 @@ fn x() void {}
17// :6:23: error: expected type 'usize', found 'bool'17// :6:23: error: expected type 'usize', found 'bool'
18//18//
19// Compile Log Output:19// Compile Log Output:
20// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn() void, (function 'x'))20// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
21// @as(comptime_int, 1000)21// @as(comptime_int, 1000)
22// @as(comptime_int, 1234)22// @as(comptime_int, 1234)
test/cases/compile_log.1.zig+1-1
...@@ -16,5 +16,5 @@ fn x() void {}...@@ -16,5 +16,5 @@ fn x() void {}
16// :4:5: note: also here16// :4:5: note: also here
17//17//
18// Compile Log Output:18// Compile Log Output:
19// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn() void, (function 'x'))19// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
20// @as(comptime_int, 1000)20// @as(comptime_int, 1000)