Skip to content

redundant_nil_coalescing false-positive on double optionals: autofix ships a compile break that lint reports clean #70

Description

@coenttb

Found by the swift-json lint lane (coordinator session 8830f961), 2026-08-10. At two sites in swift-foundations/swift-json, redundant_nil_coalescing flagged } ?? nil where the ?? nil FLATTENS a double optional (T??) returned by withContiguousStorageIfAvailable. Applying the correction produced declared closure result 'Self?' is incompatible with contextual type 'Self' — a compile break that the linter itself then reports as clean.

Fleet-wide hazard: any lane running swiftlint --fix on this rule can land a compile break, and lint gives no signal. The rule's predicate must exclude positions where the coalesced expression is itself optional (double-optional flattening). Fixture wanted: a T?? site that must NOT fire, plus the ordinary T? positive control. Consumer-side workaround used in swift-json: rewrite as .flatMap { $0 } (semantically exact, not a disable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions