diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/union.zig | 2 | ||||
| -rw-r--r-- | test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig | 8 | ||||
| -rw-r--r-- | test/cases/compile_errors/non_comptime_param_in_comptime_function.zig | 36 |
3 files changed, 41 insertions, 5 deletions
diff --git a/test/behavior/union.zig b/test/behavior/union.zig index e2078c66df..5d6b084be5 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -745,7 +745,7 @@ fn setAttribute(attr: Attribute) void { _ = attr; } -fn Setter(attr: Attribute) type { +fn Setter(comptime attr: Attribute) type { return struct { fn set() void { setAttribute(attr); diff --git a/test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig b/test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig index 7ec539dcd1..04f64c2303 100644 --- a/test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig +++ b/test/cases/compile_errors/explain_why_fn_is_called_at_comptime.zig @@ -4,12 +4,12 @@ const S = struct { }; fn bar() void {} -fn foo(a: u8) S { - return .{ .fnPtr = bar, .a = a }; +fn foo(comptime a: *u8) S { + return .{ .fnPtr = bar, .a = a.* }; } pub export fn entry() void { var a: u8 = 1; - _ = foo(a); + _ = foo(&a); } // error @@ -18,6 +18,6 @@ pub export fn entry() void { // // :12:13: error: unable to resolve comptime value // :12:13: note: argument to function being called at comptime must be comptime known -// :7:15: note: function is being called at comptime because it returns a comptime only type 'tmp.S' +// :7:25: note: function is being called at comptime because it returns a comptime only type 'tmp.S' // :2:12: note: struct requires comptime because of this field // :2:12: note: use '*const fn() void' for a function pointer type diff --git a/test/cases/compile_errors/non_comptime_param_in_comptime_function.zig b/test/cases/compile_errors/non_comptime_param_in_comptime_function.zig new file mode 100644 index 0000000000..758166dd7f --- /dev/null +++ b/test/cases/compile_errors/non_comptime_param_in_comptime_function.zig @@ -0,0 +1,36 @@ +fn F(val: anytype) type { + _ = val; + return struct {}; +} +export fn entry() void { + _ = F(void{}); +} +const S = struct { + foo: fn () void, +}; +fn bar(_: u32) S { + return undefined; +} +export fn entry1() void { + _ = bar(); +} +// prioritize other return type errors +fn foo(a: u32) callconv(.C) comptime_int { + return a; +} +export fn entry2() void { + _ = foo(1); +} + +// error +// backend=stage2 +// target=native +// +// :1:20: error: function with comptime only return type 'type' requires all parameters to be comptime +// :1:20: note: types are not available at runtime +// :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 +// :9:10: note: struct requires comptime because of this field +// :9:10: note: use '*const fn() void' for a function pointer type +// :11:8: note: param is required to be comptime +// :18:29: error: return type 'comptime_int' not allowed in function with calling convention 'C' |
