blob: 603ce497326d547334cf5a99af0ff4fbb1e2c04d (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
var runtime_int: u32 = 123;
export fn foo() void {
comptime var x: u32 = 123;
var runtime = &x;
_ = &runtime;
}
export fn bar() void {
const S = struct { u32, *const u32 };
comptime var x: u32 = 123;
const runtime: S = .{ runtime_int, &x };
_ = runtime;
}
export fn qux() void {
const S = struct { a: u32, b: *const u32 };
comptime var x: u32 = 123;
const runtime: S = .{ .a = runtime_int, .b = &x };
_ = runtime;
}
export fn baz() void {
const S = struct {
fn f(_: *const u32) void {}
};
comptime var x: u32 = 123;
S.f(&x);
}
export fn faz() void {
const S = struct {
fn f(_: anytype) void {}
};
comptime var x: u32 = 123;
S.f(&x);
}
export fn boo() *const u32 {
comptime var x: u32 = 123;
return &x;
}
export fn qar() void {
comptime var x: u32 = 123;
const y = if (runtime_int == 123) &x else undefined;
_ = y;
}
export fn bux() void {
comptime var x: [2]u32 = undefined;
x = .{ 1, 2 };
var rt: [2]u32 = undefined;
@memcpy(&rt, &x);
}
export fn far() void {
comptime var x: u32 = 123;
var rt: [2]*u32 = undefined;
const elem: *u32 = &x;
@memset(&rt, elem);
}
export fn bax() void {
comptime var x: [2]u32 = undefined;
x = .{ 1, 2 };
var rt: [2]u32 = undefined;
@memmove(&rt, &x);
}
// error
//
// :5:19: error: runtime value contains reference to comptime var
// :5:19: note: comptime var pointers are not available at runtime
// :4:14: note: 'runtime_value' points to comptime var declared here
// :12:40: error: runtime value contains reference to comptime var
// :12:40: note: comptime var pointers are not available at runtime
// :11:14: note: 'runtime_value' points to comptime var declared here
// :19:50: error: runtime value contains reference to comptime var
// :19:50: note: comptime var pointers are not available at runtime
// :18:14: note: 'runtime_value' points to comptime var declared here
// :28:9: error: runtime value contains reference to comptime var
// :28:9: note: comptime var pointers are not available at runtime
// :27:14: note: 'runtime_value' points to comptime var declared here
// :36:9: error: runtime value contains reference to comptime var
// :36:9: note: comptime var pointers are not available at runtime
// :35:14: note: 'runtime_value' points to comptime var declared here
// :41:12: error: runtime value contains reference to comptime var
// :41:12: note: comptime var pointers are not available at runtime
// :40:14: note: 'runtime_value' points to comptime var declared here
// :46:39: error: runtime value contains reference to comptime var
// :46:39: note: comptime var pointers are not available at runtime
// :45:14: note: 'runtime_value' points to comptime var declared here
// :55:18: error: runtime value contains reference to comptime var
// :55:18: note: comptime var pointers are not available at runtime
// :51:14: note: 'runtime_value' points to comptime var declared here
// :63:18: error: runtime value contains reference to comptime var
// :63:18: note: comptime var pointers are not available at runtime
// :59:14: note: 'runtime_value' points to comptime var declared here
// :71:19: error: runtime value contains reference to comptime var
// :71:19: note: comptime var pointers are not available at runtime
// :67:14: note: 'runtime_value' points to comptime var declared here
|