Skip to content

Commit 7e1ce5c

Browse files
committed
SwiftASTContext: Also display syntax errors outside of the expression buffers.
Without this, module import failures in the expression evaluator are completely opaque to the end-user and they need to look at the types log. rdar://76217088 (cherry picked from commit 2ce057c)
1 parent 6ca56a2 commit 7e1ce5c

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,52 +2858,51 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
28582858
const DiagnosticSeverity severity = SeverityForKind(diagnostic.kind);
28592859
const DiagnosticOrigin origin = eDiagnosticOriginSwift;
28602860

2861-
if (first_line > 0 && bufferID != UINT32_MAX &&
2862-
diagnostic.bufferID == bufferID && !diagnostic.bufferName.empty()) {
2863-
// Make sure the error line is in range.
2864-
if (diagnostic.line >= first_line && diagnostic.line <= last_line) {
2865-
// Need to remap the error/warning to a different line.
2866-
StreamString match;
2867-
match.Printf("%s:%u:", diagnostic.bufferName.str().c_str(),
2868-
diagnostic.line);
2869-
const size_t match_len = match.GetString().size();
2870-
size_t match_pos =
2871-
diagnostic.description.find(match.GetString().str());
2872-
if (match_pos != std::string::npos) {
2873-
// We have some <file>:<line>:" instances that need to be updated.
2874-
StreamString fixed_description;
2875-
size_t start_pos = 0;
2876-
do {
2877-
if (match_pos > start_pos)
2878-
fixed_description.Printf(
2879-
"%s", diagnostic.description.substr(start_pos, match_pos)
2880-
.c_str());
2881-
fixed_description.Printf(
2882-
"%s:%u:", diagnostic.bufferName.str().c_str(),
2883-
diagnostic.line - first_line + 1);
2884-
start_pos = match_pos + match_len;
2885-
match_pos = diagnostic.description.find(match.GetString().str(),
2886-
start_pos);
2887-
} while (match_pos != std::string::npos);
2888-
2889-
// Append any last remaining text.
2890-
if (start_pos < diagnostic.description.size())
2861+
if (first_line > 0 && bufferID != UINT32_MAX) {
2862+
// Make sure the error line is in range or in another file.
2863+
if (diagnostic.bufferID == bufferID && !diagnostic.bufferName.empty() &&
2864+
(diagnostic.line < first_line || diagnostic.line > last_line))
2865+
continue;
2866+
// Need to remap the error/warning to a different line.
2867+
StreamString match;
2868+
match.Printf("%s:%u:", diagnostic.bufferName.str().c_str(),
2869+
diagnostic.line);
2870+
const size_t match_len = match.GetString().size();
2871+
size_t match_pos = diagnostic.description.find(match.GetString().str());
2872+
if (match_pos != std::string::npos) {
2873+
// We have some <file>:<line>:" instances that need to be updated.
2874+
StreamString fixed_description;
2875+
size_t start_pos = 0;
2876+
do {
2877+
if (match_pos > start_pos)
28912878
fixed_description.Printf(
2892-
"%s", diagnostic.description
2893-
.substr(start_pos,
2894-
diagnostic.description.size() - start_pos)
2895-
.c_str());
2896-
2897-
auto new_diagnostic = std::make_unique<SwiftDiagnostic>(
2898-
fixed_description.GetData(), severity, origin, bufferID);
2899-
for (auto fixit : diagnostic.fixits)
2900-
new_diagnostic->AddFixIt(fixit);
2901-
2902-
diagnostic_manager.AddDiagnostic(std::move(new_diagnostic));
2879+
"%s",
2880+
diagnostic.description.substr(start_pos, match_pos).c_str());
2881+
fixed_description.Printf(
2882+
"%s:%u:", diagnostic.bufferName.str().c_str(),
2883+
diagnostic.line - first_line + 1);
2884+
start_pos = match_pos + match_len;
2885+
match_pos =
2886+
diagnostic.description.find(match.GetString().str(), start_pos);
2887+
} while (match_pos != std::string::npos);
2888+
2889+
// Append any last remaining text.
2890+
if (start_pos < diagnostic.description.size())
2891+
fixed_description.Printf(
2892+
"%s", diagnostic.description
2893+
.substr(start_pos,
2894+
diagnostic.description.size() - start_pos)
2895+
.c_str());
2896+
2897+
auto new_diagnostic = std::make_unique<SwiftDiagnostic>(
2898+
fixed_description.GetData(), severity, origin, bufferID);
2899+
for (auto fixit : diagnostic.fixits)
2900+
new_diagnostic->AddFixIt(fixit);
2901+
2902+
diagnostic_manager.AddDiagnostic(std::move(new_diagnostic));
2903+
if (diagnostic.kind == swift::DiagnosticKind::Error)
29032904
added_one_diagnostic = true;
29042905

2905-
continue;
2906-
}
29072906
}
29082907
}
29092908
}

lldb/test/API/lang/swift/clangimporter/expr_import/TestSwiftExprImport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ def test(self):
2323
lldbutil.run_to_source_breakpoint(self, "break here",
2424
lldb.SBFileSpec('main.swift'))
2525
self.expect("expr -- import A", error=True,
26-
substrs=['could','not','build','module'])
26+
substrs=['SYNTAX_ERROR',
27+
'could', 'not', 'build', 'module'])

0 commit comments

Comments
 (0)