mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
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`.
This commit is contained in:
parent
67caf68505
commit
f2814caaf0
2 changed files with 7 additions and 2 deletions
|
|
@ -3666,7 +3666,13 @@ fn ReverseIterator(comptime T: type) type {
|
||||||
@compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'");
|
@compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'");
|
||||||
};
|
};
|
||||||
const Element = std.meta.Elem(Pointer);
|
const Element = std.meta.Elem(Pointer);
|
||||||
const ElementPointer = @TypeOf(&@as(Pointer, undefined)[0]);
|
const ElementPointer = @Type(.{ .Pointer = ptr: {
|
||||||
|
var ptr = @typeInfo(Pointer).Pointer;
|
||||||
|
ptr.size = .One;
|
||||||
|
ptr.child = Element;
|
||||||
|
ptr.sentinel = null;
|
||||||
|
break :ptr ptr;
|
||||||
|
} });
|
||||||
return struct {
|
return struct {
|
||||||
ptr: Pointer,
|
ptr: Pointer,
|
||||||
index: usize,
|
index: usize,
|
||||||
|
|
|
||||||
|
|
@ -2104,7 +2104,6 @@ fn resolveDefinedValue(
|
||||||
const mod = sema.mod;
|
const mod = sema.mod;
|
||||||
const val = try sema.resolveValue(air_ref) orelse return null;
|
const val = try sema.resolveValue(air_ref) orelse return null;
|
||||||
if (val.isUndef(mod)) {
|
if (val.isUndef(mod)) {
|
||||||
if (block.is_typeof) return null;
|
|
||||||
return sema.failWithUseOfUndef(block, src);
|
return sema.failWithUseOfUndef(block, src);
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue