diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-10-27 19:31:45 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-10-28 13:31:16 +0300 |
| commit | c3b85e4e2f3da02d78ccb814e3025ee4b78d541b (patch) | |
| tree | 7bf5f7c960d57daa2bfae0011e888b6ed1bb23aa /test/cases/compile_errors/condition_comptime_reason_explained.zig | |
| parent | c389f8800b8707fc163efab330d2d1838f553620 (diff) | |
| download | zig-c3b85e4e2f3da02d78ccb814e3025ee4b78d541b.tar.gz zig-c3b85e4e2f3da02d78ccb814e3025ee4b78d541b.zip | |
Sema: further enhance explanation of why expr is evaluated at comptime
Diffstat (limited to 'test/cases/compile_errors/condition_comptime_reason_explained.zig')
| -rw-r--r-- | test/cases/compile_errors/condition_comptime_reason_explained.zig | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/cases/compile_errors/condition_comptime_reason_explained.zig b/test/cases/compile_errors/condition_comptime_reason_explained.zig new file mode 100644 index 0000000000..332ae8afc8 --- /dev/null +++ b/test/cases/compile_errors/condition_comptime_reason_explained.zig @@ -0,0 +1,48 @@ +const S = struct { + fnPtr: fn () void, +}; +fn bar() void {} +fn baz() void {} +var runtime: bool = true; +fn ifExpr() S { + if (runtime) { + return .{ + .fnPtr = bar, + }; + } else { + return .{ + .fnPtr = baz, + }; + } +} +pub export fn entry1() void { + _ = ifExpr(); +} +fn switchExpr() S { + switch (runtime) { + true => return .{ + .fnPtr = bar, + }, + false => return .{ + .fnPtr = baz, + }, + } +} +pub export fn entry2() void { + _ = switchExpr(); +} + +// error +// backend=stage2 +// target=native +// +// :8:9: error: unable to resolve comptime value +// :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' +// :2:12: note: struct requires comptime because of this field +// :2:12: note: use '*const fn() void' for a function pointer type +// :19:15: note: called from here +// :22:13: error: unable to resolve comptime value +// :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' +// :32:19: note: called from here |
