Commit ac55685a94
Changed files (2)
src
test
cases
compile_errors
src/Sema.zig
@@ -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);
test/cases/compile_errors/expected_optional_type_got_container.zig
@@ -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