Sema: add missing declared here note

This commit is contained in:
wooster0 2024-05-22 02:16:56 +09:00
parent f14cf13ff8
commit ac55685a94
2 changed files with 17 additions and 0 deletions

View File

@ -2238,6 +2238,7 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) {
try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
}
try addDeclaredHereNote(sema, msg, non_optional_ty);
break :msg msg;
};
return sema.failWithOwnedErrorMsg(block, msg);

View File

@ -0,0 +1,16 @@
export fn foo() void {
while (bar()) |x| {
_ = x;
}
}
const X = enum { a };
fn bar() X {
return .a;
}
// error
// backend=stage2
// target=native
//
// :2:15: error: expected optional type, found 'tmp.X'
// :6:11: note: enum declared here