@@ -46,6 +46,10 @@ template <> struct ScalarEnumerationTraits<LocalDiagID> {
4646#define DIAG (KIND, ID, Options, Text, Signature ) \
4747 io.enumCase (value, #ID, LocalDiagID::ID);
4848#include " swift/AST/DiagnosticsAll.def"
49+ // Ignore diagnostic IDs that are available in the YAML file and not
50+ // available in the `.def` file.
51+ if (io.matchEnumFallback ())
52+ value = LocalDiagID::NumDiags;
4953 }
5054};
5155
@@ -101,12 +105,19 @@ readYAML(llvm::yaml::IO &io, T &Seq, bool, Context &Ctx) {
101105 DiagnosticNode current;
102106 yamlize (io, current, true , Ctx);
103107 io.postflightElement (SaveInfo);
104- // YAML file isn't guaranteed to have diagnostics in order of their
105- // declaration in `.def` files, to accommodate that we need to leave
106- // holes in diagnostic array for diagnostics which haven't yet been
107- // localized and for the ones that have `DiagnosticNode::id`
108- // indicates their position.
109- Seq[static_cast <unsigned >(current.id )] = std::move (current.msg );
108+
109+ // A diagnostic ID might be present in YAML and not in `.def` file,
110+ // if that's the case ScalarEnumerationTraits will assign the diagnostic ID
111+ // to `LocalDiagID::NumDiags`. Since the diagnostic ID isn't available
112+ // in `.def` it shouldn't be stored in the diagnostics array.
113+ if (current.id != LocalDiagID::NumDiags) {
114+ // YAML file isn't guaranteed to have diagnostics in order of their
115+ // declaration in `.def` files, to accommodate that we need to leave
116+ // holes in diagnostic array for diagnostics which haven't yet been
117+ // localized and for the ones that have `DiagnosticNode::id`
118+ // indicates their position.
119+ Seq[static_cast <unsigned >(current.id )] = std::move (current.msg );
120+ }
110121 }
111122 }
112123 io.endSequence ();
0 commit comments