blob: 2a5868f6b1ee17ed1f1060f35e64c61b1ab002f7 (
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
|
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);
}
// error
//
// :5:19: error: runtime value contains reference to comptime var
// :5:19: note: comptime var pointers are not available at runtime
// :12:40: error: runtime value contains reference to comptime var
// :12:40: note: comptime var pointers are not available at runtime
// :19:50: error: runtime value contains reference to comptime var
// :19:50: note: comptime var pointers are not available at runtime
// :28:9: error: runtime value contains reference to comptime var
// :28:9: note: comptime var pointers are not available at runtime
// :36:9: error: runtime value contains reference to comptime var
// :36:9: note: comptime var pointers are not available at runtime
// :41:12: error: runtime value contains reference to comptime var
// :41:12: note: comptime var pointers are not available at runtime
// :46:39: error: runtime value contains reference to comptime var
// :46:39: note: comptime var pointers are not available at runtime
// :55:18: error: runtime value contains reference to comptime var
// :55:18: note: comptime var pointers are not available at runtime
// :63:18: error: runtime value contains reference to comptime var
// :63:18: note: comptime var pointers are not available at runtime
|