authorgravatar for wrongnull@gmail.comBogdan Romanyuk <wrongnull@gmail.com> 2023-11-21 14:21:32+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-21 13:21:32+02:00
log583afd6f0c01336c20dcd218cb7d14aad6894ab1
tree5b39030b656063959df4c7841ffd8be93cc44115
parentf64f3423e4a4d63838a54dfb01f5cd9ea8f68b19
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

value: update isDeclRef for anonymous declarations


2 files changed, 20 insertions(+), 2 deletions(-)

src/value.zig+2-2
...@@ -597,10 +597,10 @@ pub const Value = struct {...@@ -597,10 +597,10 @@ pub const Value = struct {
597 var check = val;597 var check = val;
598 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {598 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {
599 .ptr => |ptr| switch (ptr.addr) {599 .ptr => |ptr| switch (ptr.addr) {
600 .decl, .mut_decl, .comptime_field => return true,600 .decl, .mut_decl, .comptime_field, .anon_decl => return true,
601 .eu_payload, .opt_payload => |base| check = base.toValue(),601 .eu_payload, .opt_payload => |base| check = base.toValue(),
602 .elem, .field => |base_index| check = base_index.base.toValue(),602 .elem, .field => |base_index| check = base_index.base.toValue(),
603 else => return false,603 .int => return false,
604 },604 },
605 else => return false,605 else => return false,
606 };606 };
test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig+18
...@@ -16,6 +16,22 @@ pub export fn entry2() void {...@@ -16,6 +16,22 @@ pub export fn entry2() void {
16 _ = b;16 _ = b;
17}17}
1818
19const Int = @typeInfo(bar).Struct.backing_integer.?;
20
21const foo = enum(Int) {
22 c = @bitCast(bar{
23 .name = "test",
24 }),
25};
26
27const bar = packed struct {
28 name: [*:0]const u8,
29};
30
31pub export fn entry3() void {
32 _ = @field(foo, "c");
33}
34
19// error35// error
20// backend=stage236// backend=stage2
21// target=native37// target=native
...@@ -24,3 +40,5 @@ pub export fn entry2() void {...@@ -24,3 +40,5 @@ pub export fn entry2() void {
24// :7:16: note: operation is runtime due to this operand40// :7:16: note: operation is runtime due to this operand
25// :13:13: error: unable to evaluate comptime expression41// :13:13: error: unable to evaluate comptime expression
26// :13:16: note: operation is runtime due to this operand42// :13:16: note: operation is runtime due to this operand
43// :22:9: error: unable to evaluate comptime expression
44// :22:21: note: operation is runtime due to this operand