Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Log.ItemFormat result builders in Swift 5.8 🪵 #263

Merged
merged 1 commit into from
Apr 6, 2023

Commits on Apr 5, 2023

  1. Fix Log.ItemFormat result builders in Swift 5.8 🪵

    Due to recent improvements to Result Builders in Swift 5.8 / Xcode 14.3
    the existing `Log.ItemFormat.Builder` implementation resulted in some
    ambiguities due to it being used with two final result types:
    
    - `Formatting<Output>`: merged formatting closure witness
    - `[Formatting<Output>]`: array of formatting witnesses representing a
    group to which we apply transformations, most notably adding separators
    where we require the independent un-merged format group elements.
    
    While in the previous result builder implementation the result type was
    propagated to the inner builder closure, that is no longer the case in
    the new version which causes the ambiguity.
    
    Despite not being as compact, the simplest solution was to have two
    different builders where each specializes in its own result type. It
    causes a bit of duplication, but makes the Swift 5.8 compiler happy and
    requires no changes at the point of usage of current code, while being
    backwards compatible with Swift 5.7.
    
    ## Changes
    
    - Create new `Log.ItemFormat.GroupBuilder` and use where item format
    groups are required.
    
    - Fix and add relevant UTs.
    
    ## References
    
    - https://forums.swift.org/t/improved-result-builder-implementation-in-swift-5-8/63192
    - https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md#changes-from-the-first-revision
    p4checo committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    f137cdd View commit details
    Browse the repository at this point in the history