Bug Report
File: PlaygroundLogger/PlaygroundLogger/LogEntry+Reflection.swift
Description
The generateSummary function uses String(reflecting:) when an instance conforms to CustomStringConvertible or CustomDebugStringConvertible:
if instance is CustomStringConvertible || instance is CustomDebugStringConvertible {
return String(reflecting: instance)
}
String(reflecting:) is designed for debug output and adds surrounding double-quotes for String values and some other types. This means that when a CustomStringConvertible type's description returns a plain string, the summary shown in the Playground sidebar gets wrapped in extra quotes, showing "\"Hello\"" instead of "Hello".
This is especially confusing for users implementing CustomStringConvertible for their own types, expecting the sidebar to show their .description output directly.
Steps to Reproduce
struct Greeting: CustomStringConvertible {
var description: String { return "Hello, Playground!" }
}
let g = Greeting() // Sidebar shows: "Hello, Playground!" (with outer quotes from String(reflecting:))
// Expected: Hello, Playground!
Expected vs Actual
|
Output |
| Expected |
Hello, Playground! |
| Actual |
"Hello, Playground!" |
Root Cause
String(reflecting:) calls the debugDescription or the CustomReflectable path, which adds quotes around the output for most String-like values. For CustomStringConvertible types, the summary should use String(describing:) instead, which calls description directly without adding decoration:
// Proposed fix:
if instance is CustomStringConvertible || instance is CustomDebugStringConvertible {
return String(describing: instance) // Uses .description directly, no extra quotes
}
If it's important to retain debugDescription for CustomDebugStringConvertible-only conformers:
if instance is CustomDebugStringConvertible {
return String(reflecting: instance)
} else if instance is CustomStringConvertible {
return String(describing: instance)
}
Impact
- Severity: Medium — affects the display of virtually every user-defined type that implements
CustomStringConvertible in a Playground
- UX impact: Confusing extra quotes appear around values in the Playground sidebar results column
- Affects: All platforms (macOS, iOS, tvOS) running PlaygroundLogger
File: PlaygroundLogger/PlaygroundLogger/LogEntry+Reflection.swift (commit e8bdbb6)
Found during manual code review of the PlaygroundLogger reflection logic.
Bug Report
File:
PlaygroundLogger/PlaygroundLogger/LogEntry+Reflection.swiftDescription
The
generateSummaryfunction usesString(reflecting:)when an instance conforms toCustomStringConvertibleorCustomDebugStringConvertible:String(reflecting:)is designed for debug output and adds surrounding double-quotes forStringvalues and some other types. This means that when aCustomStringConvertibletype'sdescriptionreturns a plain string, the summary shown in the Playground sidebar gets wrapped in extra quotes, showing"\"Hello\""instead of"Hello".This is especially confusing for users implementing
CustomStringConvertiblefor their own types, expecting the sidebar to show their.descriptionoutput directly.Steps to Reproduce
Expected vs Actual
Hello, Playground!"Hello, Playground!"Root Cause
String(reflecting:)calls thedebugDescriptionor theCustomReflectablepath, which adds quotes around the output for most String-like values. ForCustomStringConvertibletypes, the summary should useString(describing:)instead, which callsdescriptiondirectly without adding decoration:If it's important to retain
debugDescriptionforCustomDebugStringConvertible-only conformers:Impact
CustomStringConvertiblein a PlaygroundFile:
PlaygroundLogger/PlaygroundLogger/LogEntry+Reflection.swift(commite8bdbb6)Found during manual code review of the PlaygroundLogger reflection logic.