swift icon indicating copy to clipboard operation
swift copied to clipboard

Improve error about extra parens with parameter packs

Open keith opened this issue 2 years ago • 0 comments

With this code:

class Store<State> {
    var currentState: State { fatalError() }
}

class CompositeStore<CompositeState, each State, OriginalState>: Store<CompositeState> {
    let store: (repeat Store<each State>)
    let combine: ((repeat (each State)) -> CompositeState)

    override var currentState: CompositeState {
        return self.combine((repeat (each store).currentState))
    }

    init(store1: (repeat Store<each State>),
         combine: @escaping (repeat (each State)) -> CompositeState)
    {
        self.store = store1
        self.combine = combine
   }
}

The call to self.combine errors with:

/tmp/foo.swift:10:29: error: cannot pass value pack expansion to non-pack parameter of type 'repeat (each State)'

The core issue here is that the extra set of parentheses need to be removed. For other types this wouldn't be an issue so I think it would be nice if somehow that was potentially recommended in the diagnostic.

Steps to reproduce

xcrun --toolchain org.swift.59202306051a swiftc /tmp/foo.swift -Xfrontend -disable-availability-checking

Environment

  • 6/5/23 main snapshot

keith avatar Jun 06 '23 22:06 keith