Quick / Nimble

A Matcher Framework for Swift and Objective-C
https://quick.github.io/Nimble/documentation/nimble/
Apache License 2.0
4.81k stars 600 forks source link

Compilation error on Linux #481

Closed lvsti closed 7 years ago

lvsti commented 7 years ago

What did you do?

I upgraded my OSS project to use Swift 4 and tried to build the thing on a Travis Linux (Ubuntu 14.04.5) machine. The package manifest for my project:

let package = Package(
    name: "MockSix",
    dependencies: [
        .package(url: "https://github.com/Quick/Quick.git", from: "1.2.0"),
        .package(url: "https://github.com/Quick/Nimble.git", from: "7.0.2"),
    ],
    targets: [
        .target(name: "MockSix", dependencies: [], path: "Sources"),
        .testTarget(
            name: "MockSixTests",
            dependencies: ["MockSix", "Quick", "Nimble"]
        )
    ],
    swiftLanguageVersions: [4]
)

What did you expect to happen?

swift build && swift test to execute properly.

What actually happened instead?

There was a compilation error while the SPM was building the dependencies:

/home/travis/build/lvsti/MockSix/.build/checkouts/Nimble.git--3756397004363768916/Sources/Nimble/Matchers/PostNotification.swift:18:27: error: ambiguous use of 'addObserver'
        self.token = self.notificationCenter.addObserver(forName: nil, object: nil, queue: nil) { [weak self] n in
                          ^

Foundation.NotificationCenter:9:15: note: found this candidate
    open func addObserver(forName name: Foundation.NSNotification.Name?, object obj: Any?, queue: Foundation.OperationQueue?, usingBlock block: @escaping (Foundation.Notification) -> Swift.Void) -> NSObjectProtocol
              ^

Foundation.NotificationCenter:10:15: note: found this candidate
    open func addObserver(forName name: Foundation.NSNotification.Name?, object obj: Any?, queue: Foundation.OperationQueue?, using block: @escaping (Foundation.Notification) -> Swift.Void) -> NSObjectProtocol
              ^

Environment

List the software versions you're using:

ikesyo commented 7 years ago

Hmm it's weird that I can't reproduce it in #482 🤔

lvsti commented 7 years ago

Well, one difference is that in your build you are building Nimble while in mine I'm building my project with Nimble as a dependency.

lvsti commented 7 years ago

On a side note, have you checked that your newly added Package@swift-4.swift manifest actually gets parsed? In my setup, if I only have that in the repo root, SPM greets me with error: root manifest not found

lvsti commented 7 years ago

FWIW, the libFoundation.a of the 4.0.2 Linux distribution of Swift indeed contains 2 symbols for NotificationCenter.addObserver:

screen shot 2017-11-14 at 23 57 58

$ swift demangle _T010Foundation18NotificationCenterC11addObserverAA16NSObjectProtocol_pAA14NSNotificationC4NameVSg03forI0_ypSg6objectAA14OperationQueueCSg5queueyAA0B0Vc10usingBlocktF
_T010Foundation18NotificationCenterC11addObserverAA16NSObjectProtocol_pAA14NSNotificationC4NameVSg03forI0_ypSg6objectAA14OperationQueueCSg5queueyAA0B0Vc10usingBlocktF ---> Foundation.NotificationCenter.addObserver(forName: Foundation.NSNotification.Name?, object: Any?, queue: Foundation.OperationQueue?, usingBlock: (Foundation.Notification) -> ()) -> Foundation.NSObjectProtocol

$ swift demangle _T010Foundation18NotificationCenterC11addObserverAA16NSObjectProtocol_pAA14NSNotificationC4NameVSg03forI0_ypSg6objectAA14OperationQueueCSg5queueyAA0B0Vc5usingtF
_T010Foundation18NotificationCenterC11addObserverAA16NSObjectProtocol_pAA14NSNotificationC4NameVSg03forI0_ypSg6objectAA14OperationQueueCSg5queueyAA0B0Vc5usingtF ---> Foundation.NotificationCenter.addObserver(forName: Foundation.NSNotification.Name?, object: Any?, queue: Foundation.OperationQueue?, using: (Foundation.Notification) -> ()) -> Foundation.NSObjectProtocol

I'm not sure if this is a bug or a feature, but I believe that by explicitly choosing one or the other form at https://github.com/Quick/Nimble/blob/master/Sources/Nimble/Matchers/PostNotification.swift#L18 instead of the trailing closure syntax would resolve the issue.

ikesyo commented 7 years ago

Hmm it's really annoying that the ambiguous overloads are introduced only in Swift 4.0.2 😞

ikesyo commented 7 years ago

Filed https://bugs.swift.org/browse/SR-6419.

ikesyo commented 7 years ago

https://github.com/apple/swift-corelibs-foundation/pull/1323