mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
sema: fix mem leaks in inferred error set handling
This commit is contained in:
parent
b00287175c
commit
5f4c9a7449
17
src/Sema.zig
17
src/Sema.zig
@ -18968,22 +18968,23 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
|
||||
.adhoc_inferred_error_set_type => {
|
||||
const ies = sema.fn_ret_ty_ies.?;
|
||||
assert(ies.func == .none);
|
||||
try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand));
|
||||
try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand));
|
||||
},
|
||||
else => if (ip.isInferredErrorSetType(err_set_ty)) {
|
||||
const ies = sema.fn_ret_ty_ies.?;
|
||||
assert(ies.func == sema.func_index);
|
||||
try addToInferredErrorSetPtr(mod, ies, sema.typeOf(uncasted_operand));
|
||||
try sema.addToInferredErrorSetPtr(ies, sema.typeOf(uncasted_operand));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn addToInferredErrorSetPtr(mod: *Module, ies: *InferredErrorSet, op_ty: Type) !void {
|
||||
const gpa = mod.gpa;
|
||||
fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {
|
||||
const arena = sema.arena;
|
||||
const mod = sema.mod;
|
||||
const ip = &mod.intern_pool;
|
||||
switch (op_ty.zigTypeTag(mod)) {
|
||||
.ErrorSet => try ies.addErrorSet(op_ty, ip, gpa),
|
||||
.ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, gpa),
|
||||
.ErrorSet => try ies.addErrorSet(op_ty, ip, arena),
|
||||
.ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, arena),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
@ -29130,7 +29131,7 @@ fn coerceInMemoryAllowedErrorSets(
|
||||
// We are trying to coerce an error set to the current function's
|
||||
// inferred error set.
|
||||
const dst_ies = sema.fn_ret_ty_ies.?;
|
||||
try dst_ies.addErrorSet(src_ty, ip, gpa);
|
||||
try dst_ies.addErrorSet(src_ty, ip, sema.arena);
|
||||
return .ok;
|
||||
}
|
||||
|
||||
@ -29140,7 +29141,7 @@ fn coerceInMemoryAllowedErrorSets(
|
||||
if (dst_ies.func == dst_ies_func_index) {
|
||||
// We are trying to coerce an error set to the current function's
|
||||
// inferred error set.
|
||||
try dst_ies.addErrorSet(src_ty, ip, gpa);
|
||||
try dst_ies.addErrorSet(src_ty, ip, sema.arena);
|
||||
return .ok;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user