diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-21 13:25:05 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-21 13:25:05 -0500 |
| commit | ce444771c5a4da1d6caab0959e5c8dd5f2df820e (patch) | |
| tree | 3095ef0192e7fb17ad36d125e7ba127cb57a6f50 | |
| parent | 8d73703d524e06e17320e025ff970c86ebc01d22 (diff) | |
| download | zig-ce444771c5a4da1d6caab0959e5c8dd5f2df820e.tar.gz zig-ce444771c5a4da1d6caab0959e5c8dd5f2df820e.zip | |
fix incorrect `@typeInfo` for sentinels
| -rw-r--r-- | src/ir.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 280ba76f2b..d60fe9ea70 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -14467,6 +14467,32 @@ static bool optional_value_is_null(ZigValue *val) { } } +static void set_optional_value_to_null(ZigValue *val) { + assert(val->special == ConstValSpecialStatic); + if (val->type->id == ZigTypeIdNull) return; // nothing to do + assert(val->type->id == ZigTypeIdOptional); + if (get_codegen_ptr_type(val->type) != nullptr) { + val->data.x_ptr.special = ConstPtrSpecialNull; + } else if (is_opt_err_set(val->type)) { + val->data.x_err_set = nullptr; + } else { + val->data.x_optional = nullptr; + } +} + +static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) { + assert(opt_val->special == ConstValSpecialStatic); + assert(opt_val->type->id == ZigTypeIdOptional); + if (payload == nullptr) { + set_optional_value_to_null(opt_val); + } else if (is_opt_err_set(opt_val->type)) { + assert(payload->type->id == ZigTypeIdErrorSet); + opt_val->data.x_err_set = payload->data.x_err_set; + } else { + opt_val->data.x_optional = payload; + } +} + static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id, bool one_possible_value) { @@ -22731,7 +22757,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent fields[6]->special = ConstValSpecialStatic; if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) { fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type); - fields[6]->data.x_optional = attrs_type->data.pointer.sentinel; + set_optional_payload(fields[6], attrs_type->data.pointer.sentinel); } else { fields[6]->type = ira->codegen->builtin_types.entry_null; } |
