authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-02 19:12:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-02 19:18:41-07:00
log91eb1af9177d774158d888484023e3bf0be65412
tree8aafa2cc145b16cfaf854980e58bbca0aff8f29f
parent3432e66faf8940bbbfc7ee24d0e17e6127e66bf6

stage2: more resilient error handling

* If more than one error is reported for the same Decl, the first error message is kept and the second one discarded. * Prevent functions from being sent to codegen backends if there were any errors resolving any of their parameter types or return type.

2 files changed, 19 insertions(+), 3 deletions(-)

src/Module.zig+12-2
......@@ -4854,7 +4854,12 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
48544854 error.GenericPoison => unreachable,
48554855 error.ComptimeReturn => unreachable,
48564856 error.ComptimeBreak => unreachable,
4857 error.AnalysisFail => {},
4857 error.AnalysisFail => {
4858 // In this case our function depends on a type that had a compile error.
4859 // We should not try to lower this function.
4860 decl.analysis = .dependency_failure;
4861 return error.AnalysisFail;
4862 },
48584863 else => |e| return e,
48594864 };
48604865
......@@ -4867,7 +4872,12 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
48674872 error.GenericPoison => unreachable,
48684873 error.ComptimeReturn => unreachable,
48694874 error.ComptimeBreak => unreachable,
4870 error.AnalysisFail => {},
4875 error.AnalysisFail => {
4876 // In this case our function depends on a type that had a compile error.
4877 // We should not try to lower this function.
4878 decl.analysis = .dependency_failure;
4879 return error.AnalysisFail;
4880 },
48714881 else => |e| return e,
48724882 };
48734883 }
src/Sema.zig+7-1
......@@ -1639,7 +1639,13 @@ fn failWithOwnedErrorMsg(sema: *Sema, block: *Block, err_msg: *Module.ErrorMsg)
16391639 sema.owner_decl.analysis = .sema_failure;
16401640 sema.owner_decl.generation = mod.generation;
16411641 }
1642 mod.failed_decls.putAssumeCapacityNoClobber(sema.owner_decl, err_msg);
1642 const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl);
1643 if (gop.found_existing) {
1644 // If there are multiple errors for the same Decl, prefer the first one added.
1645 err_msg.destroy(mod.gpa);
1646 } else {
1647 gop.value_ptr.* = err_msg;
1648 }
16431649 return error.AnalysisFail;
16441650}
16451651