let closure: ClosureType?
let otherClosure: ClosureType = {}
let pickClosure = closure ?? otherClosure
// ERROR: binary operator '??' cannot be applied to operands of type 'ClosureType?' and 'ClosureType' (aka '() -> ()')
Assuming you've merely omitted the code where you set closure to something and aren’t trying to read a variable before initializing it, I believe it's a bug... Using the "explicit" version works fine:
let closure: Closure? = nil
let otherClosure: Closure = {}
let pickClosure = closure != nil ? closure! : otherClosure
- Dave Sweeris
···
On Feb 24, 2016, at 7:37 AM, Rudolf Adamkovič via swift-users <swift-users@swift.org> wrote:
Hello there!
Today, I stumbled upon the following error:
typealias ClosureType = () -> Void
let closure: ClosureType?
let otherClosure: ClosureType = {}
let pickClosure = closure ?? otherClosure
// ERROR: binary operator '??' cannot be applied to operands of type 'ClosureType?' and 'ClosureType' (aka '() -> ()')
let closure: ClosureType?
let otherClosure: ClosureType = {}
let pickClosure = closure ?? otherClosure
// ERROR: binary operator '??' cannot be applied to operands of type 'ClosureType?' and 'ClosureType' (aka '() -> ()')
Is this a bug or a feature?
It's a known bug.
-Joe
···
On Feb 24, 2016, at 5:37 AM, Rudolf Adamkovič via swift-users <swift-users@swift.org> wrote:
On 24 Feb 2016, at 18:54, Joe Groff <jgroff@apple.com> wrote:
On Feb 24, 2016, at 5:37 AM, Rudolf Adamkovič via swift-users <swift-users@swift.org> wrote:
Hello there!
Today, I stumbled upon the following error:
typealias ClosureType = () -> Void
let closure: ClosureType?
let otherClosure: ClosureType = {}
let pickClosure = closure ?? otherClosure
// ERROR: binary operator '??' cannot be applied to operands of type 'ClosureType?' and 'ClosureType' (aka '() -> ()')