blob: 37c6b46dbaa6436e766b8f5a7db1c47ffa7af4d1 (
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
51
52
53
54
55
56
57
58
59
60
61
|
var rt_val: [5]u32 = .{ 1, 2, 3, 4, 5 };
comptime {
_ = rt_val; // fine
}
comptime {
const a = rt_val; // error
_ = a;
}
comptime {
const l = rt_val.len; // fine
@compileLog(l);
}
export fn foo() void {
_ = comptime rt_val; // error
}
export fn bar() void {
const l = comptime rt_val.len; // fine
@compileLog(l);
}
export fn baz() void {
const S = struct {
fn inner() void {
_ = comptime rt_val;
}
};
comptime S.inner(); // fine; inner comptime is a nop
S.inner(); // error
}
export fn qux() void {
const S = struct {
fn inner() void {
const a = rt_val;
_ = a;
}
};
S.inner(); // fine; everything is runtime
comptime S.inner(); // error
}
// error
//
// :8:15: error: unable to resolve comptime value
// :7:1: note: 'comptime' keyword forces comptime evaluation
// :18:9: error: unable to resolve comptime value
// :18:9: note: 'comptime' keyword forces comptime evaluation
// :29:17: error: unable to resolve comptime value
// :29:17: note: 'comptime' keyword forces comptime evaluation
// :39:23: error: unable to resolve comptime value
// :44:21: note: called at comptime from here
// :44:5: note: 'comptime' keyword forces comptime evaluation
//
// Compile Log Output:
// @as(usize, 5)
// @as(usize, 5)
|