aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/condition_comptime_reason_explained.zig
blob: 4cd12d039bce83c386de5a8eb71b0e1aa58118cc (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
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
//
// :8:9: error: unable to resolve comptime value
// :19:15: note: called at comptime from here
// :19:15: note: call to function with comptime-only return type 'tmp.S' is evaluated at comptime
// :7:13: note: return type declared here
// :2:12: note: struct requires comptime because of this field
// :2:12: note: use '*const fn () void' for a function pointer type
// :22:13: error: unable to resolve comptime value
// :32:19: note: called at comptime from here
// :32:19: note: call to function with comptime-only return type 'tmp.S' is evaluated at comptime
// :21:17: note: return type declared here
// :2:12: note: struct requires comptime because of this field
// :2:12: note: use '*const fn () void' for a function pointer type