2 Replies
      Latest reply: Sep 11, 2016 8:37 AM by eskimo RSS
      wissme Level 1 Level 1 (0 points)

        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 ?

        • Re: Problem (or bug) with local functions ?
          wissme Level 1 Level 1 (0 points)

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

          Why should there be one ?

            • Re: Problem (or bug) with local functions ?
              eskimo Apple Staff Apple Staff (6,665 points)

              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"