| 1 | var runtime_int: u32 = 123; |
| 2 | |
| 3 | export fn foo() void { |
| 4 | comptime var x: u32 = 123; |
| 5 | var runtime = &x; |
| 6 | _ = &runtime; |
| 7 | } |
| 8 | |
| 9 | export fn bar() void { |
| 10 | const S = struct { u32, *const u32 }; |
| 11 | comptime var x: u32 = 123; |
| 12 | const runtime: S = .{ runtime_int, &x }; |
| 13 | _ = runtime; |
| 14 | } |
| 15 | |
| 16 | export fn qux() void { |
| 17 | const S = struct { a: u32, b: *const u32 }; |
| 18 | comptime var x: u32 = 123; |
| 19 | const runtime: S = .{ .a = runtime_int, .b = &x }; |
| 20 | _ = runtime; |
| 21 | } |
| 22 | |
| 23 | export fn baz() void { |
| 24 | const S = struct { |
| 25 | fn f(_: *const u32) void {} |
| 26 | }; |
| 27 | comptime var x: u32 = 123; |
| 28 | S.f(&x); |
| 29 | } |
| 30 | |
| 31 | export fn faz() void { |
| 32 | const S = struct { |
| 33 | fn f(_: anytype) void {} |
| 34 | }; |
| 35 | comptime var x: u32 = 123; |
| 36 | S.f(&x); |
| 37 | } |
| 38 | |
| 39 | export fn boo() *const u32 { |
| 40 | comptime var x: u32 = 123; |
| 41 | return &x; |
| 42 | } |
| 43 | |
| 44 | export fn qar() void { |
| 45 | comptime var x: u32 = 123; |
| 46 | const y = if (runtime_int == 123) &x else undefined; |
| 47 | _ = y; |
| 48 | } |
| 49 | |
| 50 | export fn bux() void { |
| 51 | comptime var x: [2]u32 = undefined; |
| 52 | x = .{ 1, 2 }; |
| 53 | |
| 54 | var rt: [2]u32 = undefined; |
| 55 | @memcpy(&rt, &x); |
| 56 | } |
| 57 | |
| 58 | export fn far() void { |
| 59 | comptime var x: u32 = 123; |
| 60 | |
| 61 | var rt: [2]*u32 = undefined; |
| 62 | const elem: *u32 = &x; |
| 63 | @memset(&rt, elem); |
| 64 | } |
| 65 | |
| 66 | export fn bax() void { |
| 67 | comptime var x: [2]u32 = undefined; |
| 68 | x = .{ 1, 2 }; |
| 69 | |
| 70 | var rt: [2]u32 = undefined; |
| 71 | @memmove(&rt, &x); |
| 72 | } |
| 73 | |
| 74 | export fn qoo(i: u8) void { |
| 75 | comptime var x: u32 = 123; |
| 76 | const y = .{ .p = &x, .i = i }; |
| 77 | _ = y; |
| 78 | } |
| 79 | |
| 80 | var runtimeP: *bool = undefined; |
| 81 | export fn qaz() void { |
| 82 | comptime var b = true; |
| 83 | runtimeP = &b; |
| 84 | } |
| 85 | |
| 86 | // error |
| 87 | // |
| 88 | // :5:19: error: runtime value contains reference to comptime var |
| 89 | // :5:19: note: comptime var pointers are not available at runtime |
| 90 | // :4:14: note: 'runtime_value' points to comptime var declared here |
| 91 | // :12:40: error: runtime value contains reference to comptime var |
| 92 | // :12:40: note: comptime var pointers are not available at runtime |
| 93 | // :11:14: note: 'runtime_value' points to comptime var declared here |
| 94 | // :19:50: error: runtime value contains reference to comptime var |
| 95 | // :19:50: note: comptime var pointers are not available at runtime |
| 96 | // :18:14: note: 'runtime_value' points to comptime var declared here |
| 97 | // :28:9: error: runtime value contains reference to comptime var |
| 98 | // :28:9: note: comptime var pointers are not available at runtime |
| 99 | // :27:14: note: 'runtime_value' points to comptime var declared here |
| 100 | // :36:9: error: runtime value contains reference to comptime var |
| 101 | // :36:9: note: comptime var pointers are not available at runtime |
| 102 | // :35:14: note: 'runtime_value' points to comptime var declared here |
| 103 | // :41:12: error: runtime value contains reference to comptime var |
| 104 | // :41:12: note: comptime var pointers are not available at runtime |
| 105 | // :40:14: note: 'runtime_value' points to comptime var declared here |
| 106 | // :46:39: error: runtime value contains reference to comptime var |
| 107 | // :46:39: note: comptime var pointers are not available at runtime |
| 108 | // :45:14: note: 'runtime_value' points to comptime var declared here |
| 109 | // :55:18: error: runtime value contains reference to comptime var |
| 110 | // :55:18: note: comptime var pointers are not available at runtime |
| 111 | // :51:14: note: 'runtime_value' points to comptime var declared here |
| 112 | // :63:18: error: runtime value contains reference to comptime var |
| 113 | // :63:18: note: comptime var pointers are not available at runtime |
| 114 | // :59:14: note: 'runtime_value' points to comptime var declared here |
| 115 | // :71:19: error: runtime value contains reference to comptime var |
| 116 | // :71:19: note: comptime var pointers are not available at runtime |
| 117 | // :67:14: note: 'runtime_value' points to comptime var declared here |
| 118 | // :76:19: error: runtime value contains reference to comptime var |
| 119 | // :76:19: note: comptime var pointers are not available at runtime |
| 120 | // :75:14: note: 'runtime_value' points to comptime var declared here |
| 121 | // :83:16: error: runtime value contains reference to comptime var |
| 122 | // :83:16: note: comptime var pointers are not available at runtime |
| 123 | // :82:22: note: 'runtime_value' points to comptime var declared here |