Skip to content

Commit dc5a4bd

Browse files
[Localization] Print diagnostic ID name from localization
1 parent 5acd5e6 commit dc5a4bd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,16 +1114,25 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
11141114
llvm::StringRef
11151115
DiagnosticEngine::diagnosticStringFor(const DiagID id,
11161116
bool printDiagnosticName) {
1117-
// TODO: Print diagnostic names from `localization`.
1118-
if (printDiagnosticName) {
1119-
return debugDiagnosticStrings[(unsigned)id];
1120-
}
11211117
auto defaultMessage = diagnosticStrings[(unsigned)id];
1118+
auto diagnosticName = diagnosticNameStrings[(unsigned)id];
11221119
if (localization) {
11231120
auto localizedMessage =
11241121
localization.get()->getMessageOr(id, defaultMessage);
1122+
if (printDiagnosticName) {
1123+
std::string debugDiagnosticString = localizedMessage.str().c_str();
1124+
debugDiagnosticString += diagnosticName;
1125+
const std::string &localizedDebugDiagnosticString = debugDiagnosticString;
1126+
return localizedDebugDiagnosticString;
1127+
}
11251128
return localizedMessage;
11261129
}
1130+
1131+
if (printDiagnosticName) {
1132+
const std::string &debugDiagnosticString =
1133+
std::string(defaultMessage) + diagnosticName;
1134+
return debugDiagnosticString;
1135+
}
11271136
return defaultMessage;
11281137
}
11291138

test/diagnostics/Localization/fr_localization.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ var self1 = self1 // expected-note 2{{through reference here}}
1515
struct Broken {
1616
var b : Bool = True // expected-error{{impossible de trouver 'True' portée}}
1717
}
18-
var v1 : Int[1 // expected-error {{expected ']' in array type}} expected-note {{to match this opening '['}}
18+
// CHECK_NAMES: error: impossible de trouver 'True' portée [cannot_find_in_scope]{{$}}

0 commit comments

Comments
 (0)