IMHO yes, it is, and personally I'd prefer a different kind of brackets to distinguish functions and control blocks more easily:
func foo(condition: Bool, items: [Int]) -> Int [
if condition {
print("1")
return 42 // returns from a function (the nearest outer [] block)
}
items.map [ item in
print("2")
return 42 // returns from a closure (the nearest outer [] block)
]
return items.count
]
A contrived example stressing the current behaviour gotchas:
func iƒ(_ condition: Bool, execute: () -> Void) {
if condition { execute() }
}
func foo() {
let value = 42
iƒ (value == 42) {
print("1")
return
}
print("2")
if (value == 42) {
print("3")
return
}
print("4")
}
foo()
// outputs: 1, 2, 3, but not 4
Note how similar is the use site, yet how different is the resulting control flow.