diff options
| author | David Rubin <87927264+Rexicon226@users.noreply.github.com> | 2024-02-03 11:16:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-03 19:16:27 +0000 |
| commit | eb4024036d3e8e0c4a8b0dcf09da107421f3fa01 (patch) | |
| tree | 6694d3bb97fa0aaec6e947536263ce78f60e72af /src/Sema.zig | |
| parent | f2e249e92020462ac29f34fc3d45cef3dc90a3b2 (diff) | |
| download | zig-eb4024036d3e8e0c4a8b0dcf09da107421f3fa01.tar.gz zig-eb4024036d3e8e0c4a8b0dcf09da107421f3fa01.zip | |
Add error hint when looping over `ErrorUnion`
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 8a30d2bb33..35dc1089b6 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4221,6 +4221,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const msg = try sema.errMsg(block, arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)}); errdefer msg.destroy(sema.gpa); try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); + + if (object_ty.zigTypeTag(mod) == .ErrorUnion) { + try sema.errNote(block, arg_src, msg, "consider using 'try', 'catch', or 'if'", .{}); + } + break :msg msg; }; return sema.failWithOwnedErrorMsg(block, msg); |
