aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig
blob: ba9de49ebca46fe46ae1fb823f399b8926e978ae (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
var n: u8 = 5;

const S = struct {
    a: u8,
};

var a: S = .{ .a = n };

pub export fn entry1() void {
    _ = a;
}

var b: S = S{ .a = n };

pub export fn entry2() void {
    _ = b;
}

const Int = @typeInfo(bar).@"struct".backing_integer.?;

const foo = enum(Int) {
    c = @bitCast(bar{
        .name = "test",
    }),
};

const bar = packed struct {
    name: [*:0]const u8,
};

pub export fn entry3() void {
    _ = @field(foo, "c");
}

// error
//
// :7:13: error: unable to evaluate comptime expression
// :7:16: note: operation is runtime due to this operand
// :7:13: note: initializer of container-level variable must be comptime-known
// :13:13: error: unable to evaluate comptime expression
// :13:16: note: operation is runtime due to this operand
// :13:13: note: initializer of container-level variable must be comptime-known
// :22:9: error: unable to evaluate comptime expression
// :22:21: note: operation is runtime due to this operand
// :21:13: note: enum field values must be comptime-known