| author | |
| committer | |
| log | 943176bbfcf3125451fa64e082ee357c28e70413 |
| tree | 7b72a227aadaaf5d96d59240ea6c97c12cbf1753 |
| parent | 509639717ac8903fe340a02cef844383183bf716 |
| signature |
closes #214172 files changed, 18 insertions(+), 0 deletions(-)
src/Sema.zig+3| ... | ... | @@ -5428,6 +5428,9 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5428 | 5428 | const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(pt)}); |
| 5429 | 5429 | errdefer msg.destroy(sema.gpa); |
| 5430 | 5430 | try sema.errNote(destructure_src, msg, "result destructured here", .{}); |
| 5431 | if (operand_ty.zigTypeTag(pt.zcu) == .error_union) { | |
| 5432 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); | |
| 5433 | } | |
| 5431 | 5434 | break :msg msg; |
| 5432 | 5435 | }); |
| 5433 | 5436 | } |
test/cases/compile_errors/destructure_error_union.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | pub export fn entry() void { | |
| 2 | const Foo = struct { u8, u8 }; | |
| 3 | const foo: anyerror!Foo = error.Failure; | |
| 4 | const bar, const baz = foo; | |
| 5 | _ = bar; | |
| 6 | _ = baz; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :4:28: error: type 'anyerror!tmp.entry.Foo' cannot be destructured | |
| 14 | // :4:26: note: result destructured here | |
| 15 | // :4:28: note: consider using 'try', 'catch', or 'if' |