mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 05:48:31 +00:00
Sema: resolve lazy values in resolveMaybeUndefValIntable
Closes #12512 Closes #12513
This commit is contained in:
parent
b55a5007fa
commit
c1afe57d70
@ -1698,7 +1698,10 @@ fn resolveMaybeUndefValIntable(
|
||||
.elem_ptr => check = check.castTag(.elem_ptr).?.data.array_ptr,
|
||||
.eu_payload_ptr, .opt_payload_ptr => check = check.cast(Value.Payload.PayloadPtr).?.data.container_ptr,
|
||||
.generic_poison => return error.GenericPoison,
|
||||
else => return val,
|
||||
else => {
|
||||
try sema.resolveLazyValue(block, src, val);
|
||||
return val;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1325,3 +1325,25 @@ test "value in if block is comptime known" {
|
||||
};
|
||||
comptime try expect(std.mem.eql(u8, first, second));
|
||||
}
|
||||
|
||||
test "lazy sizeof is resolved in division" {
|
||||
const A = struct {
|
||||
a: u32,
|
||||
};
|
||||
const a = 2;
|
||||
try expect(@sizeOf(A) / a == 2);
|
||||
try expect(@sizeOf(A) - a == 2);
|
||||
}
|
||||
|
||||
test "lazy value is resolved as slice operand" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
const A = struct { a: u32 };
|
||||
var a: [512]u64 = undefined;
|
||||
|
||||
const ptr1 = a[0..@sizeOf(A)];
|
||||
const ptr2 = @ptrCast([*]u8, &a)[0..@sizeOf(A)];
|
||||
try expect(@ptrToInt(ptr1) == @ptrToInt(ptr2));
|
||||
try expect(ptr1.len == ptr2.len);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user