square / Cleanse

Lightweight Swift Dependency Injection Framework
Other
1.78k stars 90 forks source link

Compiler issues with latest version of XCode and Swift 4 #106

Closed CodyDunlap closed 5 years ago

CodyDunlap commented 5 years ago

We are using Swift 4 in our app and updating to the latest version of XCode with Swift 5 support seems to have introduced some new issues with Cleanse.

It appears to be similar to #83

In the configure function of a Module with a binder like binder.bind().to(factory: MainViewController.init) , we get an error message ambiguous use of 'init'

And when we use the binder.bind().to { some code } function, we also get a compiler error ambiguous use of 'to(file:line:function:factory:)'

We've tried updating to the latest version of the Cleanse library, 4.2.3 at the time of this issue, and have tried the changes mentioned in the referenced issue above. Both have had no effect.

Is there a known/recommended resolution or work-around for this?

sebastianv1 commented 5 years ago

It does appear to be the same issue, with a new compiler :)

I did a quick pass over turning each of the arity functions into:

@discardableResult public func to<P_1, P_2>(file: StaticString=#file, line: Int=#line, function: StaticString=#function, factory: @escaping ((P_1, P_2)) -> Input)  -> BindingReceipt<Input> {
   ...
    return _innerTo(file: file, line: line, function: function, provider: Provider {
     factory((
        provider1.get(),
        provider2.get()
    ))
}

Emphases on ((P_1, P_2)) where the closure more explicitly takes a tuple. This seems to work and compiles using swift 5 with the tests passing. I'll try it out tomorrow with our Square app internally to see if anything weird happens, and if not I'll open a PR to support XC 10.2 and swift 5 without any breaking API changes!

CodyDunlap commented 5 years ago

Thank you!

sebastianv1 commented 5 years ago

Resolved with #107

sebastianv1 commented 5 years ago

Published 4.2.4 to the CocoaPods specs repo