| author | |
| committer | |
| log | f14cf13ff8553030c47748a0cbd455514cd1f4a3 |
| tree | 3bc7dbe10a781f500800a45569fb5786baef6c54 |
| parent | 9ae43567a3ef14a815482ccaa2a5b412a716743e |
2 files changed, 24 insertions(+), 0 deletions(-)
src/Sema.zig+3| ... | ... | @@ -27888,6 +27888,9 @@ fn fieldCallBind( |
| 27888 | 27888 | const decl = mod.declPtr(decl_idx); |
| 27889 | 27889 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)}); |
| 27890 | 27890 | } |
| 27891 | if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) { | |
| 27892 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | |
| 27893 | } | |
| 27891 | 27894 | break :msg msg; |
| 27892 | 27895 | }; |
| 27893 | 27896 | return sema.failWithOwnedErrorMsg(block, msg); |
test/cases/compile_errors/method_call_on_error_union.zig created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | const X = struct { | |
| 2 | fn init() !X { | |
| 3 | return error.a; | |
| 4 | } | |
| 5 | ||
| 6 | fn a(x: X) void { | |
| 7 | _ = x; | |
| 8 | } | |
| 9 | }; | |
| 10 | ||
| 11 | export fn entry() void { | |
| 12 | const x = X.init(); | |
| 13 | x.a(); | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // backend=stage2 | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :13:6: error: no field or member function named 'a' in '@typeInfo(@typeInfo(@TypeOf(tmp.X.init)).Fn.return_type.?).ErrorUnion.error_set!tmp.X' | |
| 21 | // :13:6: note: consider using 'try', 'catch', or 'if' |