blob: 2e9c47522aed9ba8728352ac5e77a3106a193f2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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'
// :2:12: note: struct requires comptime because of this field
// :2:12: note: use '*const fn () void' for a function pointer type
// :32:19: note: called from here
|