| author | |
| committer | |
| log | ac55685a94b3db97e9d2eadef0432948b3c16a03 |
| tree | f318f56ad3911d2d0e5265dca5de7583787d2a77 |
| parent | f14cf13ff8553030c47748a0cbd455514cd1f4a3 |
2 files changed, 17 insertions(+), 0 deletions(-)
src/Sema.zig+1| ... | ... | @@ -2238,6 +2238,7 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non |
| 2238 | 2238 | if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 2239 | 2239 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 2240 | 2240 | } |
| 2241 | try addDeclaredHereNote(sema, msg, non_optional_ty); | |
| 2241 | 2242 | break :msg msg; |
| 2242 | 2243 | }; |
| 2243 | 2244 | return sema.failWithOwnedErrorMsg(block, msg); |
test/cases/compile_errors/expected_optional_type_got_container.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | export fn foo() void { | |
| 2 | while (bar()) |x| { | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | } | |
| 6 | const X = enum { a }; | |
| 7 | fn bar() X { | |
| 8 | return .a; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :2:15: error: expected optional type, found 'tmp.X' | |
| 16 | // :6:11: note: enum declared here |