mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 11:13:08 +00:00
Sema: adjust coercion of undefined error union payload
To no longer set the error code to undefined. This fixes the problem where an undefined single-item pointer coerced to an error union of a slice set the whole thing to undefined even though the sub-coercion to the slice would have produced a defined value.
This commit is contained in:
parent
12e1304805
commit
b59428e9f7
@ -18140,11 +18140,6 @@ fn coerce(
|
|||||||
return sema.addConstUndef(dest_ty);
|
return sema.addConstUndef(dest_ty);
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
// undefined sets the error code also to undefined.
|
|
||||||
if (is_undef) {
|
|
||||||
return sema.addConstUndef(dest_ty);
|
|
||||||
}
|
|
||||||
|
|
||||||
// T to E!T
|
// T to E!T
|
||||||
return sema.wrapErrorUnionPayload(block, dest_ty, inst, inst_src);
|
return sema.wrapErrorUnionPayload(block, dest_ty, inst, inst_src);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1372,3 +1372,13 @@ test "cast compatible optional types" {
|
|||||||
var b: ?[]const u8 = a;
|
var b: ?[]const u8 = a;
|
||||||
try expect(b == null);
|
try expect(b == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "coerce undefined single-item pointer of array to error union of slice" {
|
||||||
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const a = @as([*]u8, undefined)[0..0];
|
||||||
|
var b: error{a}![]const u8 = a;
|
||||||
|
const s = try b;
|
||||||
|
try expect(s.len == 0);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user