@@ -46,6 +46,10 @@ template <> struct ScalarEnumerationTraits<LocalDiagID> {
46
46
#define DIAG (KIND, ID, Options, Text, Signature ) \
47
47
io.enumCase (value, #ID, LocalDiagID::ID);
48
48
#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;
49
53
}
50
54
};
51
55
@@ -101,12 +105,19 @@ readYAML(llvm::yaml::IO &io, T &Seq, bool, Context &Ctx) {
101
105
DiagnosticNode current;
102
106
yamlize (io, current, true , Ctx);
103
107
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
+ }
110
121
}
111
122
}
112
123
io.endSequence ();
0 commit comments