3
votes

I am using this function

    func countFrom(from:Int, #to:Int) -> () {
        println("\(from)")
        if from < to {
             countFrom(from + 1, to: to)
        }
    }
    countFrom(1, to: 10)
}

But on compiling i get Swift Compiler Error -

Command /Applications/Xcode6-Beta2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1

And if i removed "countFrom(from + 1, to: to)", then there is no more error. What's wrong with that?

1
Should it be self.countFrom... ? - William Falcon
This is a known issue in Xcode 6 beta 4 -- nested functions that recurse crash the compiler. They mention it in the release notes and say the workaround is to "move recursive functions to the outer type or module context." - Nate Cook
"Command /Applications/Xcode6-Beta2.app/Contents/..." Well, for starters, I'd upgrade to the latest beta before asking too many questions about weird behaviour. - Matt Gibson

1 Answers

0
votes

Answer: the code is fine, the compiler is outdated. Per @Matt's comment, this works fine in Beta 4.

Console Output:

1
2
3
4
5
6
7
8
9
10