master
1const S = struct {
2 fnPtr: fn () void,
3};
4fn bar() void {}
5fn baz() void {}
6var runtime: bool = true;
7fn ifExpr() S {
8 if (runtime) {
9 return .{
10 .fnPtr = bar,
11 };
12 } else {
13 return .{
14 .fnPtr = baz,
15 };
16 }
17}
18pub export fn entry1() void {
19 _ = ifExpr();
20}
21fn switchExpr() S {
22 switch (runtime) {
23 true => return .{
24 .fnPtr = bar,
25 },
26 false => return .{
27 .fnPtr = baz,
28 },
29 }
30}
31pub export fn entry2() void {
32 _ = switchExpr();
33}
34
35// error
36//
37// :8:9: error: unable to resolve comptime value
38// :19:15: note: called at comptime from here
39// :19:15: note: call to function with comptime-only return type 'tmp.S' is evaluated at comptime
40// :7:13: note: return type declared here
41// :2:12: note: struct requires comptime because of this field
42// :2:12: note: use '*const fn () void' for a function pointer type
43// :22:13: error: unable to resolve comptime value
44// :32:19: note: called at comptime from here
45// :32:19: note: call to function with comptime-only return type 'tmp.S' is evaluated at comptime
46// :21:17: note: return type declared here
47// :2:12: note: struct requires comptime because of this field
48// :2:12: note: use '*const fn () void' for a function pointer type