diff --git a/src/Module.zig b/src/Module.zig index 24047f8798..bf54fc01fd 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -3519,14 +3519,6 @@ pub fn deinit(mod: *Module) void { pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { const gpa = mod.gpa; { - if (mod.failed_decls.contains(decl_index)) { - blk: { - const errs = mod.comp.getAllErrorsAlloc() catch break :blk; - for (errs.list) |err| Compilation.AllErrors.Message.renderToStdErr(err, .no_color); - } - // TODO restore test case triggering this panic - @panic("Zig compiler bug: attempted to destroy declaration with an attached error"); - } const decl = mod.declPtr(decl_index); log.debug("destroy {*} ({s})", .{ decl, decl.name }); _ = mod.test_functions.swapRemove(decl_index); diff --git a/src/Sema.zig b/src/Sema.zig index bc861f170a..cba14396f9 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -7174,6 +7174,7 @@ fn instantiateGenericCall( return err; }, else => { + assert(mod.monomorphed_funcs.remove(new_module_func)); { errdefer new_decl_arena.deinit(); try new_decl.finalizeNewArena(&new_decl_arena); diff --git a/test/cases/compile_errors/generic_function_instantiation_inherits_parent_branch_quota.zig b/test/cases/compile_errors/generic_function_instantiation_inherits_parent_branch_quota.zig new file mode 100644 index 0000000000..1d45ce86db --- /dev/null +++ b/test/cases/compile_errors/generic_function_instantiation_inherits_parent_branch_quota.zig @@ -0,0 +1,30 @@ +pub export fn entry1() void { + @setEvalBranchQuota(1001); + // Return type evaluation should inherit both the + // parent's branch quota and count meaning + // at least 2002 backwards branches are required. + comptime var i = 0; + inline while (i < 1000) : (i += 1) {} + _ = simple(10); +} +pub export fn entry2() void { + @setEvalBranchQuota(2001); + comptime var i = 0; + inline while (i < 1000) : (i += 1) {} + _ = simple(10); +} +fn simple(comptime n: usize) Type(n) { + return n; +} +fn Type(comptime n: usize) type { + if (n <= 1) return usize; + return Type(n - 1); +} + +// error +// backend=stage2 +// target=native +// +// :21:16: error: evaluation exceeded 1001 backwards branches +// :21:16: note: use @setEvalBranchQuota() to raise the branch limit from 1001 +// :16:34: note: called from here