zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3e084d8de352927dad182f99aeb3f166b348c192 (tree)
parent 01dba1c054724b4957778932fb5cd0df14d214b3
Author: Veikka Tuominen <git@vexu.eu>
Date:   Thu,  5 Jan 2023 13:43:06 +0200

Sema: only untyped undefined should coerce to all types

Closes #13958

Diffstat:
Msrc/Sema.zig | 2+-
Atest/cases/compile_errors/only_untyped_undef_coerces_to_all_types.zig | 11+++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -24477,7 +24477,7 @@ fn coerceExtra( return block.addBitCast(dest_ty, inst); } - const is_undef = if (maybe_inst_val) |val| val.isUndef() else false; + const is_undef = inst_ty.zigTypeTag() == .Undefined; switch (dest_ty.zigTypeTag()) { .Optional => optional: { diff --git a/test/cases/compile_errors/only_untyped_undef_coerces_to_all_types.zig b/test/cases/compile_errors/only_untyped_undef_coerces_to_all_types.zig @@ -0,0 +1,11 @@ +pub export fn entry() void { + const x: []u8 = undefined; + const y: f32 = x; + _ = y; +} + +// error +// backend=stage2 +// target=native +// +// :3:20: error: expected type 'f32', found '[]u8'