From f496ec2605017fe300ba0b46ef5ef93449281ad1 Mon Sep 17 00:00:00 2001 From: John Hui Date: Wed, 1 Oct 2025 18:11:02 -0700 Subject: [PATCH] [DiagnosticVerifier] Do not capture 'fatal error encountered' errors When the diagnostic verifier encounters a fatal error, it reports: :0: error: fatal error encountered while in -verify mode If we capture this, and fail to match this against an expected-error, the diagnostic verifier complains: :0: error: unexpected error produced: fatal error encountered while in -verify mode :0: error: diagnostic produced elsewhere: fatal error encountered while in -verify mode The current workaround is to use -verify-ignore-unknown, but that in turn may mask actual errors coming from unknown source locations. Ignoring these errors about errors removes the need for that workaround. --- lib/Frontend/DiagnosticVerifier.cpp | 5 +++++ test/Frontend/DiagnosticVerifier/expect-the-expected.swift | 3 +++ 2 files changed, 8 insertions(+) create mode 100644 test/Frontend/DiagnosticVerifier/expect-the-expected.swift diff --git a/lib/Frontend/DiagnosticVerifier.cpp b/lib/Frontend/DiagnosticVerifier.cpp index 2cf53f226cf9a..6720247c5fb46 100644 --- a/lib/Frontend/DiagnosticVerifier.cpp +++ b/lib/Frontend/DiagnosticVerifier.cpp @@ -15,6 +15,7 @@ //===----------------------------------------------------------------------===// #include "swift/Frontend/DiagnosticVerifier.h" +#include "swift/AST/DiagnosticsFrontend.h" #include "swift/Basic/Assertions.h" #include "swift/Basic/ColorUtils.h" #include "swift/Basic/SourceManager.h" @@ -1264,6 +1265,10 @@ void DiagnosticVerifier::printRemainingDiagnostics() const { /// file. void DiagnosticVerifier::handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) { + // Ignore "fatal error encountered while in -verify mode" errors, + // because there's no reason to verify them. + if (Info.ID == diag::verify_encountered_fatal.ID) + return; SmallVector fixIts; for (const auto &fixIt : Info.FixIts) { fixIts.emplace_back(SM, fixIt); diff --git a/test/Frontend/DiagnosticVerifier/expect-the-expected.swift b/test/Frontend/DiagnosticVerifier/expect-the-expected.swift new file mode 100644 index 0000000000000..b026dfebf1806 --- /dev/null +++ b/test/Frontend/DiagnosticVerifier/expect-the-expected.swift @@ -0,0 +1,3 @@ +// RUN: %target-typecheck-verify-swift + +import Expected // expected-error {{no such module 'Expected'}}