aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorWill Lillis <wlillis@umass.edu>2024-09-23 16:04:24 -0400
committerGitHub <noreply@github.com>2024-09-23 13:04:24 -0700
commit943176bbfcf3125451fa64e082ee357c28e70413 (patch)
tree7b72a227aadaaf5d96d59240ea6c97c12cbf1753 /src/Sema.zig
parent509639717ac8903fe340a02cef844383183bf716 (diff)
downloadzig-943176bbfcf3125451fa64e082ee357c28e70413.tar.gz
zig-943176bbfcf3125451fa64e082ee357c28e70413.zip
fix: Add error note when attempt is made to destructure error union (#21491)
closes #21417
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 14a4061b00..40556d2136 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -5428,6 +5428,9 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(pt)});
errdefer msg.destroy(sema.gpa);
try sema.errNote(destructure_src, msg, "result destructured here", .{});
+ if (operand_ty.zigTypeTag(pt.zcu) == .error_union) {
+ try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
+ }
break :msg msg;
});
}