| 1 | export const a: *u32 = a: { |
| 2 | var x: u32 = 123; |
| 3 | break :a &x; |
| 4 | }; |
| 5 | |
| 6 | export const b: [1]*u32 = b: { |
| 7 | var x: u32 = 123; |
| 8 | break :b .{&x}; |
| 9 | }; |
| 10 | |
| 11 | export const c: *[1]u32 = c: { |
| 12 | var x: u32 = 123; |
| 13 | break :c (&x)[0..1]; |
| 14 | }; |
| 15 | |
| 16 | export const d: *anyopaque = d: { |
| 17 | var x: u32 = 123; |
| 18 | break :d &x; |
| 19 | }; |
| 20 | |
| 21 | const S = extern struct { ptr: *u32 }; |
| 22 | export const e: S = e: { |
| 23 | var x: u32 = 123; |
| 24 | break :e .{ .ptr = &x }; |
| 25 | }; |
| 26 | |
| 27 | // The pointer constness shouldn't matter - *any* reference to a comptime var is illegal in a global's value. |
| 28 | export const f: *const u32 = f: { |
| 29 | var x: u32 = 123; |
| 30 | break :f &x; |
| 31 | }; |
| 32 | |
| 33 | // The pointer itself doesn't refer to a comptime var, but from it you can derive a pointer which does. |
| 34 | export const g: *const *const u32 = g: { |
| 35 | const valid: u32 = 123; |
| 36 | var invalid: u32 = 123; |
| 37 | const aggregate: [2]*const u32 = .{ &valid, &invalid }; |
| 38 | break :g &aggregate[0]; |
| 39 | }; |
| 40 | |
| 41 | // Mutable globals should have the same restrictions as const globals. |
| 42 | export var h: *[1]u32 = h: { |
| 43 | var x: [1]u32 = .{123}; |
| 44 | break :h &x; |
| 45 | }; |
| 46 | |
| 47 | // error |
| 48 | // |
| 49 | // :1:27: error: global variable contains reference to comptime var |
| 50 | // :2:5: note: 'a' points to comptime var declared here |
| 51 | // :6:30: error: global variable contains reference to comptime var |
| 52 | // :7:5: note: 'b[0]' points to comptime var declared here |
| 53 | // :11:30: error: global variable contains reference to comptime var |
| 54 | // :12:5: note: 'c' points to comptime var declared here |
| 55 | // :16:33: error: global variable contains reference to comptime var |
| 56 | // :17:5: note: 'd' points to comptime var declared here |
| 57 | // :22:24: error: global variable contains reference to comptime var |
| 58 | // :23:5: note: 'e.ptr' points to comptime var declared here |
| 59 | // :28:33: error: global variable contains reference to comptime var |
| 60 | // :29:5: note: 'f' points to comptime var declared here |
| 61 | // :34:40: error: global variable contains reference to comptime var |
| 62 | // :34:40: note: 'g' points to 'v0[0]', where |
| 63 | // :36:5: note: 'v0[1]' points to comptime var declared here |
| 64 | // :42:28: error: global variable contains reference to comptime var |
| 65 | // :43:5: note: 'h' points to comptime var declared here |