Skip to content

Commit 40c92eb

Browse files
committed
[DiagnosticsBridge] Treat empty category name as nil
Default value for `Category` for serialization purposes is an empty string but it should be handled as `nil` while bridging because category name cannot be empty when present.
1 parent 1c86dd7 commit 40c92eb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/ASTGen/Sources/ASTGen/DiagnosticsBridge.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,20 @@ public func addQueuedDiagnostic(
339339
}
340340
}
341341

342-
let category: DiagnosticCategory? = categoryName.map { categoryNamePtr in
342+
let category: DiagnosticCategory? = categoryName.flatMap { categoryNamePtr in
343343
let categoryNameBuffer = UnsafeBufferPointer(
344344
start: categoryNamePtr,
345345
count: categoryLength
346346
)
347347
let categoryName = String(decoding: categoryNameBuffer, as: UTF8.self)
348348

349+
// If the data comes from serialized diagnostics, it's possible that
350+
// the category name is empty because StringRef() is serialized into
351+
// an empty string.
352+
guard !categoryName.isEmpty else {
353+
return nil
354+
}
355+
349356
let documentationURL = documentationPath.map { documentationPathPtr in
350357
let documentationPathBuffer = UnsafeBufferPointer(
351358
start: documentationPathPtr,

lib/Frontend/CachedDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ llvm::Error DiagnosticSerializer::deserializeDiagnosticInfo(
617617
Kind,
618618
Info.FormatString,
619619
{},
620-
Info.Category.empty() ? StringRef() : Info.Category,
620+
Info.Category,
621621
*BICD,
622622
ChildDiagPtrs,
623623
Ranges,

0 commit comments

Comments
 (0)