authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-24 05:16:49+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-24 14:28:34+01:00
logf2814caaf04fc041a028d5ede4fb4db5ee2f19ae
tree50dfaa41d3118225cf1d3da6b31d637e657792bf
parent67caf685056bcdbbe4e696cada927615b0dd6fe9
signaturelock-open Commit is signed but in an unrecognized format.

Sema: don't allow undef values through resolveDefinedValue in typeof block

This logic is not correct in most cases. If any instruction needs to operate with different semantics within `@TypeOf`, it should be made to do so explicitly. This broke a line in `std.mem`: I have opted to fix this in std for now, since as far as I know it's not yet been discussed which operations (if any) should be special-cased like this within `@TypeOf`.

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

lib/std/mem.zig+7-1
......@@ -3666,7 +3666,13 @@ fn ReverseIterator(comptime T: type) type {
36663666 @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'");
36673667 };
36683668 const Element = std.meta.Elem(Pointer);
3669 const ElementPointer = @TypeOf(&@as(Pointer, undefined)[0]);
3669 const ElementPointer = @Type(.{ .Pointer = ptr: {
3670 var ptr = @typeInfo(Pointer).Pointer;
3671 ptr.size = .One;
3672 ptr.child = Element;
3673 ptr.sentinel = null;
3674 break :ptr ptr;
3675 } });
36703676 return struct {
36713677 ptr: Pointer,
36723678 index: usize,
src/Sema.zig-1
......@@ -2104,7 +2104,6 @@ fn resolveDefinedValue(
21042104 const mod = sema.mod;
21052105 const val = try sema.resolveValue(air_ref) orelse return null;
21062106 if (val.isUndef(mod)) {
2107 if (block.is_typeof) return null;
21082107 return sema.failWithUseOfUndef(block, src);
21092108 }
21102109 return val;