authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-17 23:28:19+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 20:25:12+02:00
log034507ef7cc492e105ca90c42686aa52bc2097e3
treea1d4b2d44b2d5f415d6ce789dcc532ffc2dffc70
parent98b3734b67739ad0e7d53500308495d53250cab0

Module: fix compile error for non-comptime-known global initializer


2 files changed, 13 insertions(+), 1 deletions(-)

src/Module.zig+1-1
...@@ -4633,7 +4633,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4633,7 +4633,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4633 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };4633 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
4634 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };4634 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
4635 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };4635 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
4636 const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, undefined);4636 const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, "global variable initializer must be comptime-known");
46374637
4638 // Note this resolves the type of the Decl, not the value; if this Decl4638 // Note this resolves the type of the Decl, not the value; if this Decl
4639 // is a struct, for example, this resolves `type` (which needs no resolution),4639 // is a struct, for example, this resolves `type` (which needs no resolution),
test/cases/compile_errors/global_variable_stored_in_global_const.zig created+12
...@@ -0,0 +1,12 @@
1var a: u32 = 2;
2const b = a;
3pub export fn entry() void {
4 _ = b;
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :2:11: error: unable to resolve comptime value
12// :2:11: note: global variable initializer must be comptime-known