@@ -6804,11 +6804,10 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
6804
6804
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6805
6805
const uncasted_operand = try sema.resolveInst(extra.operand);
6806
6806
const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
6807
- const result_ty = Type.u16;
6808
6807
6809
6808
if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| {
6810
6809
if (val.isUndef()) {
6811
- return sema.addConstUndef(result_ty );
6810
+ return sema.addConstUndef(Type.err_int );
6812
6811
}
6813
6812
switch (val.tag()) {
6814
6813
.@"error" => {
@@ -6817,14 +6816,14 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
6817
6816
.base = .{ .tag = .int_u64 },
6818
6817
.data = (try sema.mod.getErrorValue(val.castTag(.@"error").?.data.name)).value,
6819
6818
};
6820
- return sema.addConstant(result_ty , Value.initPayload(&payload.base));
6819
+ return sema.addConstant(Type.err_int , Value.initPayload(&payload.base));
6821
6820
},
6822
6821
6823
6822
// This is not a valid combination with the type `anyerror`.
6824
6823
.the_only_possible_value => unreachable,
6825
6824
6826
6825
// Assume it's already encoded as an integer.
6827
- else => return sema.addConstant(result_ty , val),
6826
+ else => return sema.addConstant(Type.err_int , val),
6828
6827
}
6829
6828
}
6830
6829
@@ -6833,14 +6832,14 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
6833
6832
if (!op_ty.isAnyError()) {
6834
6833
const names = op_ty.errorSetNames();
6835
6834
switch (names.len) {
6836
- 0 => return sema.addConstant(result_ty , Value.zero),
6837
- 1 => return sema.addIntUnsigned(result_ty , sema.mod.global_error_set.get(names[0]).?),
6835
+ 0 => return sema.addConstant(Type.err_int , Value.zero),
6836
+ 1 => return sema.addIntUnsigned(Type.err_int , sema.mod.global_error_set.get(names[0]).?),
6838
6837
else => {},
6839
6838
}
6840
6839
}
6841
6840
6842
6841
try sema.requireRuntimeBlock(block, src, operand_src);
6843
- return block.addBitCast(result_ty , operand);
6842
+ return block.addBitCast(Type.err_int , operand);
6844
6843
}
6845
6844
6846
6845
fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
@@ -6851,7 +6850,7 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
6851
6850
const src = LazySrcLoc.nodeOffset(extra.node);
6852
6851
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6853
6852
const uncasted_operand = try sema.resolveInst(extra.operand);
6854
- const operand = try sema.coerce(block, Type.u16 , uncasted_operand, operand_src);
6853
+ const operand = try sema.coerce(block, Type.err_int , uncasted_operand, operand_src);
6855
6854
const target = sema.mod.getTarget();
6856
6855
6857
6856
if (try sema.resolveDefinedValue(block, operand_src, operand)) |value| {
@@ -6868,7 +6867,10 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
6868
6867
try sema.requireRuntimeBlock(block, src, operand_src);
6869
6868
if (block.wantSafety()) {
6870
6869
const is_lt_len = try block.addUnOp(.cmp_lt_errors_len, operand);
6871
- try sema.addSafetyCheck(block, is_lt_len, .invalid_error_code);
6870
+ const zero_val = try sema.addConstant(Type.err_int, Value.zero);
6871
+ const is_non_zero = try block.addBinOp(.cmp_neq, operand, zero_val);
6872
+ const ok = try block.addBinOp(.bit_and, is_lt_len, is_non_zero);
6873
+ try sema.addSafetyCheck(block, ok, .invalid_error_code);
6872
6874
}
6873
6875
return block.addInst(.{
6874
6876
.tag = .bitcast,
@@ -17360,7 +17362,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17360
17362
17361
17363
try sema.requireRuntimeBlock(block, src, operand_src);
17362
17364
if (block.wantSafety() and !dest_ty.isAnyError() and sema.mod.comp.bin_file.options.use_llvm) {
17363
- const err_int_inst = try block.addBitCast(Type.u16 , operand);
17365
+ const err_int_inst = try block.addBitCast(Type.err_int , operand);
17364
17366
const ok = try block.addTyOp(.error_set_has_value, dest_ty, err_int_inst);
17365
17367
try sema.addSafetyCheck(block, ok, .invalid_error_code);
17366
17368
}
0 commit comments