master
1var rt_val: [5]u32 = .{ 1, 2, 3, 4, 5 };
2
3comptime {
4 _ = rt_val; // fine
5}
6
7comptime {
8 const a = rt_val; // error
9 _ = a;
10}
11
12comptime {
13 const l = rt_val.len; // fine
14 @compileLog(l);
15}
16
17export fn foo() void {
18 _ = comptime rt_val; // error
19}
20
21export fn bar() void {
22 const l = comptime rt_val.len; // fine
23 @compileLog(l);
24}
25
26export fn baz() void {
27 const S = struct {
28 fn inner() void {
29 _ = comptime rt_val;
30 }
31 };
32 comptime S.inner(); // fine; inner comptime is a nop
33 S.inner(); // error
34}
35
36export fn qux() void {
37 const S = struct {
38 fn inner() void {
39 const a = rt_val;
40 _ = a;
41 }
42 };
43 S.inner(); // fine; everything is runtime
44 comptime S.inner(); // error
45}
46
47// error
48//
49// :8:15: error: unable to resolve comptime value
50// :7:1: note: 'comptime' keyword forces comptime evaluation
51// :18:9: error: unable to resolve comptime value
52// :18:9: note: 'comptime' keyword forces comptime evaluation
53// :29:17: error: unable to resolve comptime value
54// :29:17: note: 'comptime' keyword forces comptime evaluation
55// :39:23: error: unable to resolve comptime value
56// :44:21: note: called at comptime from here
57// :44:5: note: 'comptime' keyword forces comptime evaluation
58//
59// Compile Log Output:
60// @as(usize, 5)
61// @as(usize, 5)