zig

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

commit d004ef2e5d315e102e5be93ba68443ea0877492c (tree)
parent fd838584bfdc5ef4fb57927bded9e34474bc59d3
Author: Robin Voetter <robin@voetter.nl>
Date:   Sat, 16 Oct 2021 19:55:31 +0200

stage2: make zirBoolNot return undefined when argument is undefined

Diffstat:
Msrc/Sema.zig | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -8271,12 +8271,13 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const bool_type = Type.initTag(.bool); const operand = try sema.coerce(block, bool_type, uncasted_operand, operand_src); - if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { - if (val.toBool()) { - return Air.Inst.Ref.bool_false; - } else { - return Air.Inst.Ref.bool_true; - } + if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { + return if (val.isUndef()) + sema.addConstUndef(bool_type) + else if (val.toBool()) + Air.Inst.Ref.bool_false + else + Air.Inst.Ref.bool_true; } try sema.requireRuntimeBlock(block, src); return block.addTyOp(.not, bool_type, operand);