Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting infinite loop on ScopedDisposable.init #17

Closed
chrishulbert opened this issue Sep 19, 2016 · 2 comments
Closed

Getting infinite loop on ScopedDisposable.init #17

chrishulbert opened this issue Sep 19, 2016 · 2 comments
Labels

Comments

@chrishulbert
Copy link

chrishulbert commented Sep 19, 2016

Hi, i'm getting an infinite loop when doing the following:

let disposable = someProducer.startWithNext ...
let scoped = ScopedDisposable(disposable)

It loops on ScopedDisposable's extensions' init(_ disposable: Disposable), which is here: https://github.com/ReactiveCocoa/ReactiveSwift/blob/master/Sources/Disposable.swift#L230

This init has the same signature as ScopedDisposable's non-extension init (i'm not sure how this compiles without error), and when the extension calls self.init it calls the extension init instead of the non-extension init, which causes infinite recursion.

Recommend changing the signature of the extension init to have a named argument, or even remove it? I'm not sure what the need for the extension init is, given that the normal init is fully generic already.

For reference for anyone else having this issue, you can workaround for now with: let scoped = ScopedDisposable(AnyDisposable(disposable))

Thanks

@ikesyo ikesyo added the bug label Sep 20, 2016
@ikesyo
Copy link
Member

ikesyo commented Sep 20, 2016

Thanks for reporting the issue! This is definitely a bug.

Recommend changing the signature of the extension init to have a named argument, or even remove it? I'm not sure what the need for the extension init is, given that the normal init is fully generic already.

ScopedDisposable has the generic parameter of ScopedDisposable<InnerDisposable: Disposable>, but we can't pass an instance of Disposable protocol type itself because of the limitation of Swift generics. To initialize a ScopedDisposable we needed the new AnyDisposable and pass an instance of it. With the initializer we could write the code:

let d: Disposable = SimpleDisposable()
// `scoped` is `ScopedDisposable<AnyDisposable>`.
// We can't use `ScopedDisposable<Disposable>` in current Swift.
let scoped = ScopedDisposable(d)

@ikesyo
Copy link
Member

ikesyo commented Sep 20, 2016

I've submitted the fix: #23.

@mdiep mdiep closed this as completed in #23 Sep 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants