-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Description
Basic reproducer:
import RxSwift
/// @mockable
protocol Testing {
var stream: [String: Observable<Int>] { get }
}Produces:
import RxSwift
class TestingMock: Testing {
init() { }
init(stream: [String: Observable<Int>]) {
self._stream = stream
}
private var streamSubjectKind = 0
private(set) var streamSubjectSetCallCount = 0
var streamSubject = PublishSubject<Int>() { didSet { streamSubjectSetCallCount += 1 } }
var streamReplaySubject = ReplaySubject<Int>.create(bufferSize: 1) { didSet { streamSubjectSetCallCount += 1 } }
var streamBehaviorSubject: BehaviorSubject<Int>! { didSet { streamSubjectSetCallCount += 1 } }
var _stream: [String: Observable<Int>! { didSet { streamSubjectSetCallCount += 1 } } // <- Malformed dictionary
var stream: [String: Observable<Int>] {
get {
if streamSubjectKind == 0 {
return streamSubject // <- Incorrect return type (same for others below aside from _stream)
} else if streamSubjectKind == 1 {
return streamBehaviorSubject
} else if streamSubjectKind == 2 {
return streamReplaySubject
} else {
return _stream
}
}
set {
if let val = newValue as? PublishSubject<Int> { // <- Incorrect cast
streamSubject = val
streamSubjectKind = 0
} else if let val = newValue as? BehaviorSubject<Int> {
streamBehaviorSubject = val
streamSubjectKind = 1
} else if let val = newValue as? ReplaySubject<Int> {
streamReplaySubject = val
streamSubjectKind = 2
} else {
_stream = newValue
streamSubjectKind = 3
}
}
}
}I'm assuming this is related to #307. I should note that until very recently the mock being generated for something like this was
private var _streams: [String: Observable<Int>]!
var streams: [String: Observable<Int>] {
get { _streams }
set { _streams = newValue }
}which has been working nicely. A flag to disable decomposition in the rx arguments would definitely be a nice to have.
Metadata
Metadata
Assignees
Labels
No labels