Problem (or bug) with local functions ?

The followiong runs fine in playground [beta 6] :


func g(n: Int) -> Int { return 1 }

do {

func g(n: Int) -> Int { return 2 }

print(g(n:5)) // 2 OK

}

print(g(n:5)) // 1 OK


------------- but does not run inside a do block :


do {

func h(n: Int) -> Int { return 1 }

do {

func h(n: Int) -> Int { return 2 }

print(h(n:5)) // <---- ERROR ambiguous use of h(n:)

}

print(h(n:5))

}


Is this an environment bug ?

Replies

Well, it seems to be caused by the fact that there is no toplevel binding of h(n:).

Why should there be one ?

Well, that’s strange. I originally thought that this might be tied to playgrounds (which are a bit strange when it comes to scopes) but this reproduces in a command line tool project. You should definitely file a bug about it.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"