mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
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.
This commit is contained in:
parent
3e79315d19
commit
ee4ced9683
@ -21,7 +21,7 @@ pub fn Atomic(comptime T: type) type {
|
|||||||
/// ```
|
/// ```
|
||||||
/// const RefCount = struct {
|
/// const RefCount = struct {
|
||||||
/// count: Atomic(usize),
|
/// count: Atomic(usize),
|
||||||
/// dropFn: *const fn(*RefCount) void,
|
/// dropFn: *const fn (*RefCount) void,
|
||||||
///
|
///
|
||||||
/// fn ref(self: *RefCount) void {
|
/// fn ref(self: *RefCount) void {
|
||||||
/// _ = self.count.fetchAdd(1, .Monotonic); // no ordering necessary, just updating a counter
|
/// _ = self.count.fetchAdd(1, .Monotonic); // no ordering necessary, just updating a counter
|
||||||
|
|||||||
@ -1269,10 +1269,10 @@ pub fn ensureIndexer(comptime T: type) void {
|
|||||||
if (@TypeOf(T.Key) != type) @compileError("Indexer.Key must be a type.");
|
if (@TypeOf(T.Key) != type) @compileError("Indexer.Key must be a type.");
|
||||||
if (!@hasDecl(T, "count")) @compileError("Indexer must have decl count: usize.");
|
if (!@hasDecl(T, "count")) @compileError("Indexer must have decl count: usize.");
|
||||||
if (@TypeOf(T.count) != usize) @compileError("Indexer.count must be a usize.");
|
if (@TypeOf(T.count) != usize) @compileError("Indexer.count must be a usize.");
|
||||||
if (!@hasDecl(T, "indexOf")) @compileError("Indexer.indexOf must be a fn(Key)usize.");
|
if (!@hasDecl(T, "indexOf")) @compileError("Indexer.indexOf must be a fn (Key) usize.");
|
||||||
if (@TypeOf(T.indexOf) != fn (T.Key) usize) @compileError("Indexer must have decl indexOf: fn(Key)usize.");
|
if (@TypeOf(T.indexOf) != fn (T.Key) usize) @compileError("Indexer must have decl indexOf: fn (Key) usize.");
|
||||||
if (!@hasDecl(T, "keyForIndex")) @compileError("Indexer must have decl keyForIndex: fn(usize)Key.");
|
if (!@hasDecl(T, "keyForIndex")) @compileError("Indexer must have decl keyForIndex: fn (usize) Key.");
|
||||||
if (@TypeOf(T.keyForIndex) != fn (usize) T.Key) @compileError("Indexer.keyForIndex must be a fn(usize)Key.");
|
if (@TypeOf(T.keyForIndex) != fn (usize) T.Key) @compileError("Indexer.keyForIndex must be a fn (usize) Key.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2255,11 +2255,11 @@ test "pointer" {
|
|||||||
const FnPtr = *align(1) const fn () void;
|
const FnPtr = *align(1) const fn () void;
|
||||||
{
|
{
|
||||||
const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
|
const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
|
||||||
try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
|
try expectFmt("pointer: fn () void@deadbeef\n", "pointer: {}\n", .{value});
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
|
const value = @as(FnPtr, @ptrFromInt(0xdeadbeef));
|
||||||
try expectFmt("pointer: fn() void@deadbeef\n", "pointer: {}\n", .{value});
|
try expectFmt("pointer: fn () void@deadbeef\n", "pointer: {}\n", .{value});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -969,9 +969,9 @@ test "std.meta.Float" {
|
|||||||
/// correspond to the argument types.
|
/// correspond to the argument types.
|
||||||
///
|
///
|
||||||
/// Examples:
|
/// Examples:
|
||||||
/// - `ArgsTuple(fn() void)` ⇒ `tuple { }`
|
/// - `ArgsTuple(fn () void)` ⇒ `tuple { }`
|
||||||
/// - `ArgsTuple(fn(a: u32) u32)` ⇒ `tuple { u32 }`
|
/// - `ArgsTuple(fn (a: u32) u32)` ⇒ `tuple { u32 }`
|
||||||
/// - `ArgsTuple(fn(a: u32, b: f16) noreturn)` ⇒ `tuple { u32, f16 }`
|
/// - `ArgsTuple(fn (a: u32, b: f16) noreturn)` ⇒ `tuple { u32, f16 }`
|
||||||
pub fn ArgsTuple(comptime Function: type) type {
|
pub fn ArgsTuple(comptime Function: type) type {
|
||||||
const info = @typeInfo(Function);
|
const info = @typeInfo(Function);
|
||||||
if (info != .Fn)
|
if (info != .Fn)
|
||||||
|
|||||||
@ -7,7 +7,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
|
|||||||
return struct {
|
return struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
// Allow for compareFn to be fn(anytype, anytype) anytype
|
// Allow for compareFn to be fn (anytype, anytype) anytype
|
||||||
// which allows the convenient use of std.math.order.
|
// which allows the convenient use of std.math.order.
|
||||||
fn compare(a: Key, b: Key) Order {
|
fn compare(a: Key, b: Key) Order {
|
||||||
return compareFn(a, b);
|
return compareFn(a, b);
|
||||||
|
|||||||
@ -3255,23 +3255,23 @@ pub const Node = struct {
|
|||||||
@"break",
|
@"break",
|
||||||
/// `return lhs`. lhs can be omitted. rhs is unused.
|
/// `return lhs`. lhs can be omitted. rhs is unused.
|
||||||
@"return",
|
@"return",
|
||||||
/// `fn(a: lhs) rhs`. lhs can be omitted.
|
/// `fn (a: lhs) rhs`. lhs can be omitted.
|
||||||
/// anytype and ... parameters are omitted from the AST tree.
|
/// anytype and ... parameters are omitted from the AST tree.
|
||||||
/// main_token is the `fn` keyword.
|
/// main_token is the `fn` keyword.
|
||||||
/// extern function declarations use this tag.
|
/// extern function declarations use this tag.
|
||||||
fn_proto_simple,
|
fn_proto_simple,
|
||||||
/// `fn(a: b, c: d) rhs`. `sub_range_list[lhs]`.
|
/// `fn (a: b, c: d) rhs`. `sub_range_list[lhs]`.
|
||||||
/// anytype and ... parameters are omitted from the AST tree.
|
/// anytype and ... parameters are omitted from the AST tree.
|
||||||
/// main_token is the `fn` keyword.
|
/// main_token is the `fn` keyword.
|
||||||
/// extern function declarations use this tag.
|
/// extern function declarations use this tag.
|
||||||
fn_proto_multi,
|
fn_proto_multi,
|
||||||
/// `fn(a: b) rhs addrspace(e) linksection(f) callconv(g)`. `FnProtoOne[lhs]`.
|
/// `fn (a: b) rhs addrspace(e) linksection(f) callconv(g)`. `FnProtoOne[lhs]`.
|
||||||
/// zero or one parameters.
|
/// zero or one parameters.
|
||||||
/// anytype and ... parameters are omitted from the AST tree.
|
/// anytype and ... parameters are omitted from the AST tree.
|
||||||
/// main_token is the `fn` keyword.
|
/// main_token is the `fn` keyword.
|
||||||
/// extern function declarations use this tag.
|
/// extern function declarations use this tag.
|
||||||
fn_proto_one,
|
fn_proto_one,
|
||||||
/// `fn(a: b, c: d) rhs addrspace(e) linksection(f) callconv(g)`. `FnProto[lhs]`.
|
/// `fn (a: b, c: d) rhs addrspace(e) linksection(f) callconv(g)`. `FnProto[lhs]`.
|
||||||
/// anytype and ... parameters are omitted from the AST tree.
|
/// anytype and ... parameters are omitted from the AST tree.
|
||||||
/// main_token is the `fn` keyword.
|
/// main_token is the `fn` keyword.
|
||||||
/// extern function declarations use this tag.
|
/// extern function declarations use this tag.
|
||||||
|
|||||||
@ -5251,8 +5251,8 @@ test "zig fmt: make single-line if no trailing comma, fmt: off" {
|
|||||||
\\ }
|
\\ }
|
||||||
\\}
|
\\}
|
||||||
\\
|
\\
|
||||||
\\const fn_no_comma = fn(i32, i32)void;
|
\\const fn_no_comma = fn (i32, i32) void;
|
||||||
\\const fn_trailing_comma = fn(i32, i32,)void;
|
\\const fn_trailing_comma = fn (i32, i32,) void;
|
||||||
\\
|
\\
|
||||||
\\fn fn_calls() void {
|
\\fn fn_calls() void {
|
||||||
\\ fn add(x: i32, y: i32,) i32 { x + y };
|
\\ fn add(x: i32, y: i32,) i32 { x + y };
|
||||||
|
|||||||
@ -6722,7 +6722,7 @@ fn zirCall(
|
|||||||
{
|
{
|
||||||
const return_ty = sema.typeOf(call_inst);
|
const return_ty = sema.typeOf(call_inst);
|
||||||
if (modifier != .always_tail and return_ty.isNoReturn(mod))
|
if (modifier != .always_tail and return_ty.isNoReturn(mod))
|
||||||
return call_inst; // call to "fn(...) noreturn", don't pop
|
return call_inst; // call to "fn (...) noreturn", don't pop
|
||||||
|
|
||||||
// TODO: we don't fix up the error trace for always_tail correctly, we should be doing it
|
// TODO: we don't fix up the error trace for always_tail correctly, we should be doing it
|
||||||
// *before* the recursive call. This will be a bit tricky to do and probably requires
|
// *before* the recursive call. This will be a bit tricky to do and probably requires
|
||||||
|
|||||||
@ -364,7 +364,7 @@ pub const Type = struct {
|
|||||||
if (fn_info.is_noinline) {
|
if (fn_info.is_noinline) {
|
||||||
try writer.writeAll("noinline ");
|
try writer.writeAll("noinline ");
|
||||||
}
|
}
|
||||||
try writer.writeAll("fn(");
|
try writer.writeAll("fn (");
|
||||||
const param_types = fn_info.param_types.get(&mod.intern_pool);
|
const param_types = fn_info.param_types.get(&mod.intern_pool);
|
||||||
for (param_types, 0..) |param_ty, i| {
|
for (param_types, 0..) |param_ty, i| {
|
||||||
if (i != 0) try writer.writeAll(", ");
|
if (i != 0) try writer.writeAll(", ");
|
||||||
|
|||||||
@ -1194,7 +1194,7 @@ test "implicit ptr to *anyopaque" {
|
|||||||
try expect(c.* == 1);
|
try expect(c.* == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "return null from fn() anyerror!?&T" {
|
test "return null from fn () anyerror!?&T" {
|
||||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||||
|
|||||||
@ -73,18 +73,18 @@ test "basic" {
|
|||||||
try expectEqualStrings("*usize", @typeName(*usize));
|
try expectEqualStrings("*usize", @typeName(*usize));
|
||||||
try expectEqualStrings("[]u8", @typeName([]u8));
|
try expectEqualStrings("[]u8", @typeName([]u8));
|
||||||
|
|
||||||
try expectEqualStrings("fn() void", @typeName(fn () void));
|
try expectEqualStrings("fn () void", @typeName(fn () void));
|
||||||
try expectEqualStrings("fn(u32) void", @typeName(fn (u32) void));
|
try expectEqualStrings("fn (u32) void", @typeName(fn (u32) void));
|
||||||
try expectEqualStrings("fn(u32) void", @typeName(fn (a: u32) void));
|
try expectEqualStrings("fn (u32) void", @typeName(fn (a: u32) void));
|
||||||
|
|
||||||
try expectEqualStrings("fn(comptime u32) void", @typeName(fn (comptime u32) void));
|
try expectEqualStrings("fn (comptime u32) void", @typeName(fn (comptime u32) void));
|
||||||
try expectEqualStrings("fn(noalias []u8) void", @typeName(fn (noalias []u8) void));
|
try expectEqualStrings("fn (noalias []u8) void", @typeName(fn (noalias []u8) void));
|
||||||
|
|
||||||
try expectEqualStrings("fn() align(32) void", @typeName(fn () align(32) void));
|
try expectEqualStrings("fn () align(32) void", @typeName(fn () align(32) void));
|
||||||
try expectEqualStrings("fn() callconv(.C) void", @typeName(fn () callconv(.C) void));
|
try expectEqualStrings("fn () callconv(.C) void", @typeName(fn () callconv(.C) void));
|
||||||
try expectEqualStrings("fn() align(32) callconv(.C) void", @typeName(fn () align(32) callconv(.C) void));
|
try expectEqualStrings("fn () align(32) callconv(.C) void", @typeName(fn () align(32) callconv(.C) void));
|
||||||
try expectEqualStrings("fn(...) align(32) callconv(.C) void", @typeName(fn (...) align(32) callconv(.C) void));
|
try expectEqualStrings("fn (...) align(32) callconv(.C) void", @typeName(fn (...) align(32) callconv(.C) void));
|
||||||
try expectEqualStrings("fn(u32, ...) align(32) callconv(.C) void", @typeName(fn (u32, ...) align(32) callconv(.C) void));
|
try expectEqualStrings("fn (u32, ...) align(32) callconv(.C) void", @typeName(fn (u32, ...) align(32) callconv(.C) void));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "top level decl" {
|
test "top level decl" {
|
||||||
@ -108,17 +108,17 @@ test "top level decl" {
|
|||||||
|
|
||||||
// regular fn, without error
|
// regular fn, without error
|
||||||
try expectEqualStrings(
|
try expectEqualStrings(
|
||||||
"fn() void",
|
"fn () void",
|
||||||
@typeName(@TypeOf(regular)),
|
@typeName(@TypeOf(regular)),
|
||||||
);
|
);
|
||||||
// regular fn inside struct, with error
|
// regular fn inside struct, with error
|
||||||
try expectEqualStrings(
|
try expectEqualStrings(
|
||||||
"fn() @typeInfo(@typeInfo(@TypeOf(behavior.typename.B.doTest)).Fn.return_type.?).ErrorUnion.error_set!void",
|
"fn () @typeInfo(@typeInfo(@TypeOf(behavior.typename.B.doTest)).Fn.return_type.?).ErrorUnion.error_set!void",
|
||||||
@typeName(@TypeOf(B.doTest)),
|
@typeName(@TypeOf(B.doTest)),
|
||||||
);
|
);
|
||||||
// generic fn
|
// generic fn
|
||||||
try expectEqualStrings(
|
try expectEqualStrings(
|
||||||
"fn(comptime type) type",
|
"fn (comptime type) type",
|
||||||
@typeName(@TypeOf(TypeFromFn)),
|
@typeName(@TypeOf(TypeFromFn)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -234,7 +234,7 @@ test "comptime parameters not converted to anytype in function type" {
|
|||||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||||
|
|
||||||
const T = fn (fn (type) void, void) void;
|
const T = fn (fn (type) void, void) void;
|
||||||
try expectEqualStrings("fn(comptime fn(comptime type) void, void) void", @typeName(T));
|
try expectEqualStrings("fn (comptime fn (comptime type) void, void) void", @typeName(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "anon name strategy used in sub expression" {
|
test "anon name strategy used in sub expression" {
|
||||||
|
|||||||
@ -16,4 +16,4 @@ pub export fn entry() void {
|
|||||||
// :8:12: error: variable of type 'tmp.S1' must be const or comptime
|
// :8:12: error: variable of type 'tmp.S1' must be const or comptime
|
||||||
// :2:8: note: struct requires comptime because of this field
|
// :2:8: note: struct requires comptime because of this field
|
||||||
// :5:8: note: struct requires comptime because of this field
|
// :5:8: note: struct requires comptime because of this field
|
||||||
// :5:8: note: use '*const fn() void' for a function pointer type
|
// :5:8: note: use '*const fn () void' for a function pointer type
|
||||||
|
|||||||
@ -8,5 +8,5 @@ inline fn b() void {}
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:9: error: variable of type '*const fn() callconv(.Inline) void' must be const or comptime
|
// :2:9: error: variable of type '*const fn () callconv(.Inline) void' must be const or comptime
|
||||||
// :2:9: note: function has inline calling convention
|
// :2:9: note: function has inline calling convention
|
||||||
|
|||||||
@ -9,4 +9,4 @@ fn afunc() void {}
|
|||||||
// backend=stage1
|
// backend=stage1
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// tmp.zig:4:32: error: expected async function, found 'fn() void'
|
// tmp.zig:4:32: error: expected async function, found 'fn () void'
|
||||||
|
|||||||
@ -11,7 +11,7 @@ pub export fn entry2() void {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:9: error: cannot call optional type '?fn() void'
|
// :3:9: error: cannot call optional type '?fn () void'
|
||||||
// :3:9: note: consider using '.?', 'orelse' or 'if'
|
// :3:9: note: consider using '.?', 'orelse' or 'if'
|
||||||
// :7:9: error: cannot call optional type '?*const fn() void'
|
// :7:9: error: cannot call optional type '?*const fn () void'
|
||||||
// :7:9: note: consider using '.?', 'orelse' or 'if'
|
// :7:9: note: consider using '.?', 'orelse' or 'if'
|
||||||
|
|||||||
@ -17,10 +17,10 @@ export fn entry2() void {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :6:9: error: expected type '?*const fn(i8) void', found '?*const fn(u64) void'
|
// :6:9: error: expected type '?*const fn (i8) void', found '?*const fn (u64) void'
|
||||||
// :6:9: note: pointer type child 'fn(u64) void' cannot cast into pointer type child 'fn(i8) void'
|
// :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void'
|
||||||
// :6:9: note: parameter 0 'u64' cannot cast into 'i8'
|
// :6:9: note: parameter 0 'u64' cannot cast into 'i8'
|
||||||
// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
|
// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
|
||||||
// :13:9: error: expected type '?*const fn(u63) void', found '?*const fn(u64) void'
|
// :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
|
||||||
// :13:9: note: pointer type child 'fn(u64) void' cannot cast into pointer type child 'fn(u63) void'
|
// :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
|
||||||
// :13:9: note: parameter 0 'u64' cannot cast into 'u63'
|
// :13:9: note: parameter 0 'u64' cannot cast into 'u63'
|
||||||
|
|||||||
@ -14,7 +14,7 @@ fn bar(comptime _: i32, _: i32) void {}
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:9: error: expected type 'fn(comptime i32, comptime i32) void', found 'fn(comptime i32, i32) void'
|
// :3:9: error: expected type 'fn (comptime i32, comptime i32) void', found 'fn (comptime i32, i32) void'
|
||||||
// :3:9: note: non-comptime parameter 1 cannot cast into a comptime parameter
|
// :3:9: note: non-comptime parameter 1 cannot cast into a comptime parameter
|
||||||
// :7:9: error: expected type 'fn(i32, i32) void', found 'fn(comptime i32, comptime i32) void'
|
// :7:9: error: expected type 'fn (i32, i32) void', found 'fn (comptime i32, comptime i32) void'
|
||||||
// :7:9: note: generic function cannot cast into a non-generic function
|
// :7:9: note: generic function cannot cast into a non-generic function
|
||||||
|
|||||||
@ -20,6 +20,6 @@ pub export fn entry1() void {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:6: error: parameter of type '*const fn(anytype) void' must be declared comptime
|
// :3:6: error: parameter of type '*const fn (anytype) void' must be declared comptime
|
||||||
// :3:6: note: function is generic
|
// :3:6: note: function is generic
|
||||||
// :10:34: error: parameter of type 'comptime_int' must be declared comptime
|
// :10:34: error: parameter of type 'comptime_int' must be declared comptime
|
||||||
|
|||||||
@ -40,11 +40,11 @@ pub export fn entry2() void {
|
|||||||
// :8:9: note: condition in comptime branch must be comptime-known
|
// :8:9: note: condition in comptime branch must be comptime-known
|
||||||
// :7:13: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
|
// :7:13: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
|
||||||
// :2:12: note: struct requires comptime because of this field
|
// :2:12: note: struct requires comptime because of this field
|
||||||
// :2:12: note: use '*const fn() void' for a function pointer type
|
// :2:12: note: use '*const fn () void' for a function pointer type
|
||||||
// :19:15: note: called from here
|
// :19:15: note: called from here
|
||||||
// :22:13: error: unable to resolve comptime value
|
// :22:13: error: unable to resolve comptime value
|
||||||
// :22:13: note: condition in comptime switch must be comptime-known
|
// :22:13: note: condition in comptime switch must be comptime-known
|
||||||
// :21:17: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
|
// :21:17: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
|
||||||
// :2:12: note: struct requires comptime because of this field
|
// :2:12: note: struct requires comptime because of this field
|
||||||
// :2:12: note: use '*const fn() void' for a function pointer type
|
// :2:12: note: use '*const fn () void' for a function pointer type
|
||||||
// :32:19: note: called from here
|
// :32:19: note: called from here
|
||||||
|
|||||||
@ -46,9 +46,9 @@ pub export fn entry() void {
|
|||||||
//
|
//
|
||||||
// :11:22: error: comparison of 'void' with null
|
// :11:22: error: comparison of 'void' with null
|
||||||
// :25:51: error: cannot load opaque type 'anyopaque'
|
// :25:51: error: cannot load opaque type 'anyopaque'
|
||||||
// :25:51: error: values of type 'fn(*anyopaque, usize, u8, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
|
// :25:51: error: values of type 'fn (*anyopaque, usize, u8, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
|
||||||
// :25:51: note: use '*const fn(*anyopaque, usize, u8, usize) ?[*]u8' for a function pointer type
|
// :25:51: note: use '*const fn (*anyopaque, usize, u8, usize) ?[*]u8' for a function pointer type
|
||||||
// :25:51: error: values of type 'fn(*anyopaque, []u8, u8, usize, usize) bool' must be comptime-known, but operand value is runtime-known
|
// :25:51: error: values of type 'fn (*anyopaque, []u8, u8, usize, usize) bool' must be comptime-known, but operand value is runtime-known
|
||||||
// :25:51: note: use '*const fn(*anyopaque, []u8, u8, usize, usize) bool' for a function pointer type
|
// :25:51: note: use '*const fn (*anyopaque, []u8, u8, usize, usize) bool' for a function pointer type
|
||||||
// :25:51: error: values of type 'fn(*anyopaque, []u8, u8, usize) void' must be comptime-known, but operand value is runtime-known
|
// :25:51: error: values of type 'fn (*anyopaque, []u8, u8, usize) void' must be comptime-known, but operand value is runtime-known
|
||||||
// :25:51: note: use '*const fn(*anyopaque, []u8, u8, usize) void' for a function pointer type
|
// :25:51: note: use '*const fn (*anyopaque, []u8, u8, usize) void' for a function pointer type
|
||||||
|
|||||||
@ -12,6 +12,6 @@ export fn entry() void {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :8:18: error: expected type '*const fn(i32) void', found '*const fn(bool) void'
|
// :8:18: error: expected type '*const fn (i32) void', found '*const fn (bool) void'
|
||||||
// :8:18: note: pointer type child 'fn(bool) void' cannot cast into pointer type child 'fn(i32) void'
|
// :8:18: note: pointer type child 'fn (bool) void' cannot cast into pointer type child 'fn (i32) void'
|
||||||
// :8:18: note: parameter 0 'bool' cannot cast into 'i32'
|
// :8:18: note: parameter 0 'bool' cannot cast into 'i32'
|
||||||
|
|||||||
@ -20,4 +20,4 @@ pub export fn entry() void {
|
|||||||
// :12:13: note: argument to function being called at comptime must be comptime-known
|
// :12:13: note: argument to function being called at comptime must be comptime-known
|
||||||
// :7:25: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
|
// :7:25: note: expression is evaluated at comptime because the function returns a comptime-only type 'tmp.S'
|
||||||
// :2:12: note: struct requires comptime because of this field
|
// :2:12: note: struct requires comptime because of this field
|
||||||
// :2:12: note: use '*const fn() void' for a function pointer type
|
// :2:12: note: use '*const fn () void' for a function pointer type
|
||||||
|
|||||||
@ -17,5 +17,5 @@ export fn entry() usize {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :1:38: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
|
// :1:38: error: expected type 'fn (i32) i32', found 'fn (i32) callconv(.C) i32'
|
||||||
// :1:38: note: calling convention 'C' cannot cast into calling convention 'Unspecified'
|
// :1:38: note: calling convention 'C' cannot cast into calling convention 'Unspecified'
|
||||||
|
|||||||
@ -14,4 +14,4 @@ comptime {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :7:15: error: expected type 'type', found 'fn() type'
|
// :7:15: error: expected type 'type', found 'fn () type'
|
||||||
|
|||||||
@ -13,9 +13,9 @@ export fn wrong_return_type() void {
|
|||||||
// backend=stage2,llvm
|
// backend=stage2,llvm
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:25: error: expected type 'fn() void', found 'fn(i32) void'
|
// :3:25: error: expected type 'fn () void', found 'fn (i32) void'
|
||||||
// :3:25: note: function with 1 parameters cannot cast into a function with 0 parameters
|
// :3:25: note: function with 1 parameters cannot cast into a function with 0 parameters
|
||||||
// :6:28: error: expected type 'fn(f32) void', found 'fn(i32) void'
|
// :6:28: error: expected type 'fn (f32) void', found 'fn (i32) void'
|
||||||
// :6:28: note: parameter 0 'i32' cannot cast into 'f32'
|
// :6:28: note: parameter 0 'i32' cannot cast into 'f32'
|
||||||
// :9:24: error: expected type 'fn() i32', found 'fn(i32) void'
|
// :9:24: error: expected type 'fn () i32', found 'fn (i32) void'
|
||||||
// :9:24: note: return type 'void' cannot cast into return type 'i32'
|
// :9:24: note: return type 'void' cannot cast into return type 'i32'
|
||||||
|
|||||||
@ -9,4 +9,4 @@ pub export fn entry() void {
|
|||||||
// target=native
|
// target=native
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
//
|
//
|
||||||
// :5:12: error: expected type 'type', found 'fn() type'
|
// :5:12: error: expected type 'type', found 'fn () type'
|
||||||
|
|||||||
@ -9,4 +9,4 @@ export fn entry() usize {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:21: error: operator > not allowed for type 'fn() void'
|
// :2:21: error: operator > not allowed for type 'fn () void'
|
||||||
|
|||||||
@ -9,4 +9,4 @@ pub export fn entry() void {
|
|||||||
// backend=llvm
|
// backend=llvm
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :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'
|
// :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'
|
||||||
|
|||||||
@ -19,6 +19,6 @@ pub export fn entry() void {
|
|||||||
// backend=llvm
|
// backend=llvm
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :15:28: error: expected type '*const fn(comptime type, u8, u8) u32', found '*const fn(void, u8, u8) u32'
|
// :15:28: error: expected type '*const fn (comptime type, u8, u8) u32', found '*const fn (void, u8, u8) u32'
|
||||||
// :15:28: note: pointer type child 'fn(void, u8, u8) u32' cannot cast into pointer type child 'fn(comptime type, u8, u8) u32'
|
// :15:28: note: pointer type child 'fn (void, u8, u8) u32' cannot cast into pointer type child 'fn (comptime type, u8, u8) u32'
|
||||||
// :15:28: note: non-generic function cannot cast into a generic function
|
// :15:28: note: non-generic function cannot cast into a generic function
|
||||||
|
|||||||
@ -14,7 +14,7 @@ fn bar(noalias _: *i32, _: *i32) void {}
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:9: error: expected type 'fn(noalias *i32, noalias *i32) void', found 'fn(noalias *i32, *i32) void'
|
// :3:9: error: expected type 'fn (noalias *i32, noalias *i32) void', found 'fn (noalias *i32, *i32) void'
|
||||||
// :3:9: note: regular parameter 1 cannot cast into a noalias parameter
|
// :3:9: note: regular parameter 1 cannot cast into a noalias parameter
|
||||||
// :7:9: error: expected type 'fn(*i32, *i32) void', found 'fn(noalias *i32, noalias *i32) void'
|
// :7:9: error: expected type 'fn (*i32, *i32) void', found 'fn (noalias *i32, noalias *i32) void'
|
||||||
// :7:9: note: noalias parameter 0 cannot cast into a regular parameter
|
// :7:9: note: noalias parameter 0 cannot cast into a regular parameter
|
||||||
|
|||||||
@ -31,6 +31,6 @@ export fn entry2() void {
|
|||||||
// :1:6: note: param 'val' is required to be comptime
|
// :1:6: note: param 'val' is required to be comptime
|
||||||
// :11:16: error: function with comptime-only return type 'tmp.S' requires all parameters to be comptime
|
// :11:16: error: function with comptime-only return type 'tmp.S' requires all parameters to be comptime
|
||||||
// :9:10: note: struct requires comptime because of this field
|
// :9:10: note: struct requires comptime because of this field
|
||||||
// :9:10: note: use '*const fn() void' for a function pointer type
|
// :9:10: note: use '*const fn () void' for a function pointer type
|
||||||
// :11:8: note: param is required to be comptime
|
// :11:8: note: param is required to be comptime
|
||||||
// :18:29: error: return type 'comptime_int' not allowed in function with calling convention 'C'
|
// :18:29: error: return type 'comptime_int' not allowed in function with calling convention 'C'
|
||||||
|
|||||||
@ -12,9 +12,9 @@ comptime {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:8: error: extern structs cannot contain fields of type 'fn() callconv(.C) void'
|
// :2:8: error: extern structs cannot contain fields of type 'fn () callconv(.C) void'
|
||||||
// :2:8: note: type has no guaranteed in-memory representation
|
// :2:8: note: type has no guaranteed in-memory representation
|
||||||
// :2:8: note: use '*const ' to make a function pointer type
|
// :2:8: note: use '*const ' to make a function pointer type
|
||||||
// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn() callconv(.C) void'
|
// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn () callconv(.C) void'
|
||||||
// :8:13: note: type has no guaranteed in-memory representation
|
// :8:13: note: type has no guaranteed in-memory representation
|
||||||
// :8:13: note: use '*const ' to make a function pointer type
|
// :8:13: note: use '*const ' to make a function pointer type
|
||||||
|
|||||||
@ -84,7 +84,7 @@ export fn entry12() void {
|
|||||||
// :59:18: note: union declared here
|
// :59:18: note: union declared here
|
||||||
// :28:12: error: packed structs cannot contain fields of type '?anyerror'
|
// :28:12: error: packed structs cannot contain fields of type '?anyerror'
|
||||||
// :28:12: note: type has no guaranteed in-memory representation
|
// :28:12: note: type has no guaranteed in-memory representation
|
||||||
// :38:12: error: packed structs cannot contain fields of type 'fn() void'
|
// :38:12: error: packed structs cannot contain fields of type 'fn () void'
|
||||||
// :38:12: note: type has no guaranteed in-memory representation
|
// :38:12: note: type has no guaranteed in-memory representation
|
||||||
// :38:12: note: use '*const ' to make a function pointer type
|
// :38:12: note: use '*const ' to make a function pointer type
|
||||||
// :65:31: error: packed structs cannot contain fields of type '[]u8'
|
// :65:31: error: packed structs cannot contain fields of type '[]u8'
|
||||||
|
|||||||
@ -12,5 +12,5 @@ fn alignedSmall() align(4) i32 {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=x86_64-linux
|
// target=x86_64-linux
|
||||||
//
|
//
|
||||||
// :2:35: error: expected type '*const fn() align(8) i32', found '*const fn() align(4) i32'
|
// :2:35: error: expected type '*const fn () align(8) i32', found '*const fn () align(4) i32'
|
||||||
// :2:35: note: pointer alignment '4' cannot cast into pointer alignment '8'
|
// :2:35: note: pointer alignment '4' cannot cast into pointer alignment '8'
|
||||||
|
|||||||
@ -24,9 +24,9 @@ pub export fn entry3() void {
|
|||||||
// target=native
|
// target=native
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
//
|
//
|
||||||
// :7:10: error: values of type '[2]fn() void' must be comptime-known, but index value is runtime-known
|
// :7:10: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
|
||||||
// :7:10: note: use '*const fn() void' for a function pointer type
|
// :7:10: note: use '*const fn () void' for a function pointer type
|
||||||
// :15:18: error: values of type '[2]fn() void' must be comptime-known, but index value is runtime-known
|
// :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
|
||||||
// :15:17: note: use '*const fn() void' for a function pointer type
|
// :15:17: note: use '*const fn () void' for a function pointer type
|
||||||
// :21:19: error: values of type '[2]fn() void' must be comptime-known, but index value is runtime-known
|
// :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
|
||||||
// :21:18: note: use '*const fn() void' for a function pointer type
|
// :21:18: note: use '*const fn () void' for a function pointer type
|
||||||
|
|||||||
@ -13,5 +13,5 @@ pub export fn entry() void {
|
|||||||
//
|
//
|
||||||
// :6:12: error: variable of type 'tmp.S' must be const or comptime
|
// :6:12: error: variable of type 'tmp.S' must be const or comptime
|
||||||
// :2:8: note: struct requires comptime because of this field
|
// :2:8: note: struct requires comptime because of this field
|
||||||
// :2:8: note: use '*const fn() void' for a function pointer type
|
// :2:8: note: use '*const fn () void' for a function pointer type
|
||||||
// :3:8: note: struct requires comptime because of this field
|
// :3:8: note: struct requires comptime because of this field
|
||||||
|
|||||||
@ -13,5 +13,5 @@ pub export fn entry() void {
|
|||||||
//
|
//
|
||||||
// :6:12: error: variable of type 'tmp.U' must be const or comptime
|
// :6:12: error: variable of type 'tmp.U' must be const or comptime
|
||||||
// :2:8: note: union requires comptime because of this field
|
// :2:8: note: union requires comptime because of this field
|
||||||
// :2:8: note: use '*const fn() void' for a function pointer type
|
// :2:8: note: use '*const fn () void' for a function pointer type
|
||||||
// :3:8: note: union requires comptime because of this field
|
// :3:8: note: union requires comptime because of this field
|
||||||
|
|||||||
@ -8,4 +8,4 @@ export fn entry() void {
|
|||||||
// backend=stage1
|
// backend=stage1
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime
|
// tmp.zig:1:9: error: parameter of type 'fn (anytype) anytype' must be declared comptime
|
||||||
|
|||||||
@ -12,6 +12,6 @@ export fn entry() void {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :8:7: error: expected type '*const fn(*const u8) void', found '*const fn(u8) void'
|
// :8:7: error: expected type '*const fn (*const u8) void', found '*const fn (u8) void'
|
||||||
// :8:7: note: pointer type child 'fn(u8) void' cannot cast into pointer type child 'fn(*const u8) void'
|
// :8:7: note: pointer type child 'fn (u8) void' cannot cast into pointer type child 'fn (*const u8) void'
|
||||||
// :8:7: note: parameter 0 'u8' cannot cast into '*const u8'
|
// :8:7: note: parameter 0 'u8' cannot cast into '*const u8'
|
||||||
|
|||||||
@ -10,6 +10,6 @@ export fn main() void {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :5:22: error: expected type '?fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'
|
// :5:22: error: expected type '?fn ([*c]u8, ...) callconv(.C) void', found 'fn ([*:0]u8, ...) callconv(.C) void'
|
||||||
// :5:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8'
|
// :5:22: note: parameter 0 '[*:0]u8' cannot cast into '[*c]u8'
|
||||||
// :5:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'
|
// :5:22: note: '[*c]u8' could have null values which are illegal in type '[*:0]u8'
|
||||||
|
|||||||
@ -16,5 +16,5 @@ export fn entry() usize {
|
|||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :1:28: error: expected type 'fn() void', found 'fn() i32'
|
// :1:28: error: expected type 'fn () void', found 'fn () i32'
|
||||||
// :1:28: note: return type 'i32' cannot cast into return type 'void'
|
// :1:28: note: return type 'i32' cannot cast into return type 'void'
|
||||||
|
|||||||
@ -17,6 +17,6 @@ fn x() void {}
|
|||||||
// :6:23: error: expected type 'usize', found 'bool'
|
// :6:23: error: expected type 'usize', found 'bool'
|
||||||
//
|
//
|
||||||
// Compile Log Output:
|
// Compile Log Output:
|
||||||
// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn() void, (function 'x'))
|
// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
|
||||||
// @as(comptime_int, 1000)
|
// @as(comptime_int, 1000)
|
||||||
// @as(comptime_int, 1234)
|
// @as(comptime_int, 1234)
|
||||||
|
|||||||
@ -16,5 +16,5 @@ fn x() void {}
|
|||||||
// :4:5: note: also here
|
// :4:5: note: also here
|
||||||
//
|
//
|
||||||
// Compile Log Output:
|
// Compile Log Output:
|
||||||
// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn() void, (function 'x'))
|
// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
|
||||||
// @as(comptime_int, 1000)
|
// @as(comptime_int, 1000)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user