swift: fail to build Observable extenion method on RxSwift

Description in Xcode 15 beta 6,RxSwiftExt Package is starting to fail building. It turns out that specific method declaration extension is problematic.

Steps to reproduce

I made a simple example to reproduce. or you can try to build RxSwiftExt Package.

import RxSwift

extension Observable {
    func test() -> Observable<Bool> {
        // error: Cannot convert return expression of type 'Observable<Element>' to return type 'Observable<Bool>'
        // error: Cannot specialize non-generic type 'Observable<Element>'
        return Observable<Bool>.empty()
    }
}

but this two code is passing without error.

// fully unqualified
extension Observable {
    func test() -> Observable<Bool> {
        return .empty()
    }
}

// fully qualified
extension Observable {
    func test() -> Observable<Bool> {
        return RxSwift.Observable<Bool>.empty()
    }
}

Expected behavior

build success without error

Environment

  • Swift compiler version info

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.2 clang-1500.0.40.1) Target: arm64-apple-macosx13.0

  • Xcode version info

Xcode 15.0 Build version 15A5219j

  • Deployment target: N/A

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 14
  • Comments: 29 (24 by maintainers)

Commits related to this issue

Most upvoted comments

FYI this is a regression from Xcode 15 Beta 5 where this worked with no issues

Still an issue in Beta 7

image

I believe this is a constraint system bug that was introduced by https://github.com/apple/swift/pull/66657, and this bug manifested with RxSwift when Foundation started exporting the Observation library in Xcode 15 Beta 6. The bug is specific to writing an explicitly specialized Observable<X> in expressions in a situation where the constraint system has to perform overload resolution in order to determine what the type refers to (e.g. because there’s an import Foundation that also surfaces an Observable declaration), which is why explicitly specifying RxSwift.Observable<X>.empty works around the problem. Regular type annotations should be unaffected, which is why removing Observable<X> from the expression and using the leading dot syntax works around the issue. Removing the specialization may also workaround the problem, though I have not attempted that yet to confirm whether or not it works.

@xedin is working on a fix.

Still an issue in Xcode 15 Beta 8

Any chance we could get some clarity about this by anyone from the Core Team? The release date is right around the corner and this was already fixed and then regressed during the beta itself. @DougGregor

The release/5.9 branch corresponds to potential point releases of Swift 5.9. The fix is not in Swift 5.9.0.

Thank you:)

Sorry to go over my last question again but I truly don’t understand the semantics🥲

Will a point release of 5.9.1 necessarily only come in the 15.1 version of Xcode itself? Or is there no way to tell?

Thanks for the patience and pardon my ignorance on the topic 😃

In my case, after updating RxSwiftExt to 6.2.1 the issue was gone

Yup, we added a workaround, but it would be nice if the breakage wouldn’t be happened from the get go

Would be interesting to test after the next public release of Swift

In my case, after updating RxSwiftExt to 6.2.1 the issue was gone

I think this is worse opening is a separate issue, might be a bug on main that is only reproducible in assert builds. I am going to build a 5.9 toolchain, let’s see if it’s reproducible there as well.