From 55ba335e0ffc2af76bf0743d98f5a959ccce0409 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 11 Mar 2022 19:31:29 -0700 Subject: Sema: fix resolution of inferred error sets 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. --- src/type.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index ae9ca31e9f..04bd015bcc 100644 --- a/src/type.zig +++ b/src/type.zig @@ -559,9 +559,9 @@ pub const Type = extern union { .error_set_inferred => { // Inferred error sets are only equal if both are inferred // and they originate from the exact same function. - const a_set = a.castTag(.error_set_inferred).?.data; - const b_set = (b.castTag(.error_set_inferred) orelse return false).data; - return a_set.func == b_set.func; + const a_ies = a.castTag(.error_set_inferred).?.data; + const b_ies = (b.castTag(.error_set_inferred) orelse return false).data; + return a_ies == b_ies; }, .anyerror => { @@ -983,10 +983,10 @@ pub const Type = extern union { .error_set_inferred => { // inferred error sets are compared using their data pointer - const set = ty.castTag(.error_set_inferred).?.data; + const ies: *Module.Fn.InferredErrorSet = ty.castTag(.error_set_inferred).?.data; std.hash.autoHash(hasher, std.builtin.TypeId.ErrorSet); std.hash.autoHash(hasher, Tag.error_set_inferred); - std.hash.autoHash(hasher, set.func); + std.hash.autoHash(hasher, ies); }, .@"opaque" => { -- cgit v1.2.3