From 583afd6f0c01336c20dcd218cb7d14aad6894ab1 Mon Sep 17 00:00:00 2001 From: Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:21:32 +0300 Subject: [PATCH] value: update isDeclRef for anonymous declarations --- src/value.zig | 4 ++-- .../unable_to_evaluate_comptime_expr.zig | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/value.zig b/src/value.zig index 256b537573aa1337511f2ef1a1640f1bdc9d57c5..5fcb3270ff86ba760c2a4a8fab384b24be3f1b38 100644 --- a/src/value.zig +++ b/src/value.zig @@ -597,10 +597,10 @@ pub const Value = struct { var check = val; while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) { .ptr => |ptr| switch (ptr.addr) { - .decl, .mut_decl, .comptime_field => return true, + .decl, .mut_decl, .comptime_field, .anon_decl => return true, .eu_payload, .opt_payload => |base| check = base.toValue(), .elem, .field => |base_index| check = base_index.base.toValue(), - else => return false, + .int => return false, }, else => return false, }; diff --git a/test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig b/test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig index 1c439316bcfe5ab3338a5d57a6806cd6ffad86e5..4d93a42ae1e84804df880189d266afeec37e3648 100644 --- a/test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig +++ b/test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig @@ -16,6 +16,22 @@ pub export fn entry2() void { _ = b; } +const Int = @typeInfo(bar).Struct.backing_integer.?; + +const foo = enum(Int) { + c = @bitCast(bar{ + .name = "test", + }), +}; + +const bar = packed struct { + name: [*:0]const u8, +}; + +pub export fn entry3() void { + _ = @field(foo, "c"); +} + // error // backend=stage2 // target=native @@ -24,3 +40,5 @@ pub export fn entry2() void { // :7:16: note: operation is runtime due to this operand // :13:13: error: unable to evaluate comptime expression // :13:16: note: operation is runtime due to this operand +// :22:9: error: unable to evaluate comptime expression +// :22:21: note: operation is runtime due to this operand -- 2.54.0