zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 034507ef7cc492e105ca90c42686aa52bc2097e3 (tree)
parent 98b3734b67739ad0e7d53500308495d53250cab0
Author: Veikka Tuominen <git@vexu.eu>
Date:   Thu, 17 Nov 2022 23:28:19 +0200

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

Diffstat:
Msrc/Module.zig | 2+-
Atest/cases/compile_errors/global_variable_stored_in_global_const.zig | 12++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)

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