Here is a contrived reduction of my problem

func mainFunction(closure:(Int) -> Int) -> Int {


    func closureDoubled(_ n: Int) -> Int {

        let result = closure(n)

        return 2*result

    }


    let temp1 = closure(1)

    let temp2 = closureDoubled(1)

    return temp1+temp2

}

The line "let result = closure(n)" is refused by the compiler with the
error message "declaration over non closing parameter may allow it to
escape".

First off, while I know what an escaping or a non-escaping closure is, I
find this error message utterly impossible to understand. To begin with,
the sentence "non closing parameter" is meaningless to me.

In any case, my main function is passed a non-escaping closure. I want to
call it from inside it, the compiler is ok with. I want also to call it
from a nested function, but the compiler disagrees.

I believe the compiler should not complain here. Did I miss anything?

Jean-Denis
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to