Short description of the issue:
there is a weird error happening in this code. when i try to multiply an Int and a CGFloat and assign it to a CGFloat, i get an error that the binary operator * is not working there. that is a correct error. but when i do the same as the first line in a subscribe onNext: block, then instead of that error, i get a extraneous argument onNext.
correct error

wrong error

Expected outcome:
i should be getting the same operator * error, whether its the first line in the block or not.
What actually happens:
i get a different error, one thats not related to the actual error.
Self contained code example that reproduces the issue:
let i: Int = 3
let f: CGFloat = 4.0
var o: CGFloat
Observable.just("test")
.subscribe(onNext: { s in
o = i * f
})
.disposed(by: DisposeBag())
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
4.0.0
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
9.0.1 (9A1004)
Installation method:
I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)
Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)
Hi @pvinis ,
This is compile time error o = i * f because Swift doesn't support automatic type conversions and so is this var o: CGFloat since compiler can't prove o is initialized in scope.
The weird error you are seeing is just a consequence of first error, so this is Swift compiler inconvenience. Yes, we've hit this often and it's irritating.
¯\_(ツ)_/¯
i have reported it here https://bugs.swift.org/browse/SR-6246
@pvinis, it should be: o = CGFloat(i) * f and there isn't error, as well Kruno told you
well yes I understand that. it's still a swift bug. so I kept this issue closed and I just linked the issue over there for future reference and for anyone interested.
Old issue, but this thread solved it for me. basically you have add the onError: closure, and the compiler will point out the correct error message.
let i: Int = 3
let f: CGFloat = 4.0
var o: CGFloat
Observable.just("test")
.subscribe(
onNext: { s in o = i * f },
onError: nil
).disposed(by: DisposeBag())
Most helpful comment
Hi @pvinis ,
This is compile time error
o = i * fbecause Swift doesn't support automatic type conversions and so is thisvar o: CGFloatsince compiler can't proveois initialized in scope.The weird error you are seeing is just a consequence of first error, so this is Swift compiler inconvenience. Yes, we've hit this often and it's irritating.
¯\_(ツ)_/¯