Skip to content

[Localization] Ignore diagnostic IDs that are available in YAML and not in .def #33316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/AST/LocalizationFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ template <> struct ScalarEnumerationTraits<LocalDiagID> {
#define DIAG(KIND, ID, Options, Text, Signature) \
io.enumCase(value, #ID, LocalDiagID::ID);
#include "swift/AST/DiagnosticsAll.def"
// Ignore diagnostic IDs that are available in the YAML file and not
// available in the `.def` file.
if (io.matchEnumFallback())
value = LocalDiagID::NumDiags;
}
};

Expand Down Expand Up @@ -101,12 +105,19 @@ readYAML(llvm::yaml::IO &io, T &Seq, bool, Context &Ctx) {
DiagnosticNode current;
yamlize(io, current, true, Ctx);
io.postflightElement(SaveInfo);
// YAML file isn't guaranteed to have diagnostics in order of their
// declaration in `.def` files, to accommodate that we need to leave
// holes in diagnostic array for diagnostics which haven't yet been
// localized and for the ones that have `DiagnosticNode::id`
// indicates their position.
Seq[static_cast<unsigned>(current.id)] = std::move(current.msg);

// A diagnostic ID might be present in YAML and not in `.def` file,
// if that's the case ScalarEnumerationTraits will assign the diagnostic ID
// to `LocalDiagID::NumDiags`. Since the diagnostic ID isn't available
// in `.def` it shouldn't be stored in the diagnostics array.
if (current.id != LocalDiagID::NumDiags) {
// YAML file isn't guaranteed to have diagnostics in order of their
// declaration in `.def` files, to accommodate that we need to leave
// holes in diagnostic array for diagnostics which haven't yet been
// localized and for the ones that have `DiagnosticNode::id`
// indicates their position.
Seq[static_cast<unsigned>(current.id)] = std::move(current.msg);
}
}
}
io.endSequence();
Expand Down
3 changes: 3 additions & 0 deletions test/diagnostics/Localization/Inputs/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#
#===----------------------------------------------------------------------===#

- id: "not_available_in_def"
msg: "Shouldn't be produced"

- id: "lex_unterminated_string"
msg: "unterminated string literal"

Expand Down