Commit ac55685a94

wooster0 <wooster0@proton.me>
2024-05-21 19:16:56
Sema: add missing declared here note
1 parent f14cf13
Changed files (2)
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