diff --git a/src/Module.zig b/src/Module.zig index 9a5a23b5772b..f3c5cc0c4e82 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -2771,6 +2771,11 @@ pub fn resolvePeerTypes(self: *Module, scope: *Scope, instructions: []*Inst) !Ty chosen = candidate; continue; } + + // error set widening + // TODO remove: dest is chosen, cur is canditade + if (chosen.ty.zigTypeTag() == .ErrorSet and candidate.ty.zigTypeTag() == .ErrorSet) {} + if (chosen.ty.isInt() and candidate.ty.isInt() and chosen.ty.isSignedInt() == candidate.ty.isSignedInt()) diff --git a/src/type.zig b/src/type.zig index a6aa0dfd445b..50100f6c16cf 100644 --- a/src/type.zig +++ b/src/type.zig @@ -240,6 +240,8 @@ pub const Type = extern union { return true else return false; + } else if (b.tag() == .anyerror) { + return false; } if (a.tag() == .error_set_single and b.tag() == .error_set_single) { diff --git a/src/zir_sema.zig b/src/zir_sema.zig index 2bbeef3a2f81..5b04ae3cddf4 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -886,8 +886,8 @@ fn analyzeInstMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) switch (lhs_fields) { .err_single => |name| { - const entry = mod.global_error_set.get(name).?; - payload.fields.putAssumeCapacity(name, entry); + const num = mod.global_error_set.get(name).?; + payload.fields.putAssumeCapacity(name, num); }, .multiple => |multiple| { var it = multiple.iterator(); @@ -900,8 +900,8 @@ fn analyzeInstMergeErrorSets(mod: *Module, scope: *Scope, inst: *zir.Inst.BinOp) switch (rhs_fields) { .err_single => |name| { - const entry = try mod.getErrorValue(name); - payload.fields.putAssumeCapacity(entry.key, entry.value); + const num = mod.global_error_set.get(name).?; + payload.fields.putAssumeCapacity(name, num); }, .multiple => |multiple| { var it = multiple.iterator(); @@ -1823,13 +1823,10 @@ fn analyzeInstCmp( if (!is_equality_cmp) { return mod.fail(scope, inst.base.src, "{} operator not allowed for errors", .{@tagName(op)}); } - const lhs_comptime = lhs.ty.cast(Type.Payload.ErrorSetSingle); - const rhs_comptime = rhs.ty.cast(Type.Payload.ErrorSetSingle); - if (lhs_comptime != null and rhs_comptime != null) { - if (op == .eq) - return mod.constBool(scope, inst.base.src, !std.mem.eql(u8, lhs_comptime.?.name, rhs_comptime.?.name)) - else - return mod.constBool(scope, inst.base.src, std.mem.eql(u8, lhs_comptime.?.name, rhs_comptime.?.name)); + const lhs_val = lhs.value(); + const rhs_val = rhs.value(); + if (lhs_val != null and rhs_val != null) { + return mod.constBool(scope, inst.base.src, !(lhs_val.?.cast(Value.Payload.Error).?.value == rhs_val.?.cast(Value.Payload.Error).?.value) == (op == .eq)); } return mod.fail(scope, inst.base.src, "TODO runtime error comparison", .{}); } else if (lhs.ty.isNumeric() and rhs.ty.isNumeric()) {