Skip to content

Bug: generateSummary uses String(reflecting:) for CustomStringConvertible — causes misleading double-quotes in summary output #81

@AkshatRaj00

Description

@AkshatRaj00

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions