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
- Don't fully spec the return values. Needed because Xcode 15beta6 has a conflict between RxSwift.Observable and Foundation.Observable. By using the static member names, swift is able to infer the corr... — committed to FountainheadMobileSolutions/RxSwiftExt by rudedogdhc a year ago
- [PreCheck] Filter out macro declarations from result set Move logic from `ConstraintGenerator::visitOverloadedDeclRefExpr` to pre-check to avoid including macro declarations referenced without `#`. T... — committed to xedin/swift by xedin 10 months ago
- [PreCheck] Filter out macro declarations from result set Move logic from `ConstraintGenerator::visitOverloadedDeclRefExpr` to pre-check to avoid including macro declarations referenced without `#`. T... — committed to xedin/swift by xedin 10 months ago
- Add RxSwift to remove ambiguity imports Foundation which causes issue described here: https://github.com/apple/swift/issues/67815#issuecomment-1701944076 — committed to barkinglabs/RxBluetoothKit by philfi 9 months ago
- Add RxSwift to remove ambiguity imports Foundation which causes issue described here: https://github.com/apple/swift/issues/67815#issuecomment-1701944076 — committed to barkinglabs/RxBluetoothKit by philfi 9 months ago
- Xcode 15/Swift 5.9 (#3) * Add RxSwift to remove ambiguity imports Foundation which causes issue described here: https://github.com/apple/swift/issues/67815#issuecomment-1701944076 * Create cont... — committed to barkinglabs/RxBluetoothKit by philfi 9 months ago
- Xcode 15/Swift 5.9 에서 발생하는 Observable Ambiguity 대응 https://github.com/apple/swift/issues/67815 — committed to socar-inc/RxBluetoothKit by socar-narr 8 months ago
FYI this is a regression from Xcode 15 Beta 5 where this worked with no issues
Still an issue in Beta 7
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 animport Foundation
that also surfaces anObservable
declaration), which is why explicitly specifyingRxSwift.Observable<X>.empty
works around the problem. Regular type annotations should be unaffected, which is why removingObservable<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
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 😃
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.