Skip to content

Commit 493d102

Browse files
[Localization] Ignore diagnostic IDs that are available in YAML and not in .def
1 parent 1d4009a commit 493d102

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/AST/LocalizationFormat.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.outputting() && io.matchEnumFallback())
52+
value = LocalDiagID::NumDiags;
4953
}
5054
};
5155

@@ -101,12 +105,15 @@ 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+
if (current.id != LocalDiagID::NumDiags) {
110+
// YAML file isn't guaranteed to have diagnostics in order of their
111+
// declaration in `.def` files, to accommodate that we need to leave
112+
// holes in diagnostic array for diagnostics which haven't yet been
113+
// localized and for the ones that have `DiagnosticNode::id`
114+
// indicates their position.
115+
Seq[static_cast<unsigned>(current.id)] = std::move(current.msg);
116+
}
110117
}
111118
}
112119
io.endSequence();

test/diagnostics/Localization/Inputs/en.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#
1818
#===----------------------------------------------------------------------===#
1919

20+
- id: "not_available_in_def"
21+
msg: "Shouldn't be produced"
22+
2023
- id: "lex_unterminated_string"
2124
msg: "unterminated string literal"
2225

0 commit comments

Comments
 (0)