mirror of
https://github.com/ziglang/zig.git
synced 2025-12-14 02:03:08 +00:00
Introduce `Module.ensureFuncBodyAnalyzed` and corresponding `Sema` function. This mirrors `ensureDeclAnalyzed` except also waits until the function body has been semantically analyzed, meaning that inferred error sets will have been populated. Resolving error sets can now emit a "unable to resolve inferred error set" error instead of producing an incorrect error set type. Resolving error sets now calls `ensureFuncBodyAnalyzed`. Closes #11046. `coerceInMemoryAllowedErrorSets` now does a lot more work to avoid resolving an inferred error set if possible. Same with `wrapErrorUnionSet`. Inferred error set types no longer check the `func` field to determine if they are equal. That was incorrect because an inline or comptime function call produces a unique error set which has the same `*Module.Fn` value for this field. Instead we use the `*Module.Fn.InferredErrorSet` pointers to test equality of inferred error sets.
22 lines
578 B
Zig
22 lines
578 B
Zig
const builtin = @import("builtin");
|
|
|
|
fn foo() !void {
|
|
var a = true;
|
|
if (a) return error.Foo;
|
|
return error.Bar;
|
|
}
|
|
fn bar() !void {
|
|
try foo();
|
|
}
|
|
|
|
test "fixed" {
|
|
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
|
|
bar() catch |err| switch (err) {
|
|
error.Foo => {}, // error: expected (inferred error set of bar), found error{Foo}
|
|
error.Bar => {},
|
|
};
|
|
}
|