2

I have a strange behavior within swift playground.

When I enter this lines of code

println("test 1" + "test 2" + "test 3" + "test 4") //compiles
println("test 1" + "test 2" + "test 3" + "test 4" + "test 5") //compiles
println("test 1" + "test 2" + "test 3" + "test 4" + "test 5" + "test 6") //error!

The last line of code does not compile. The error is:

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

Am I doing something wrong, or is this some kind of a bug? It seems like the limit for println() is 5 string concatenations?

nemke
  • 2,440
  • 3
  • 37
  • 57

1 Answers1

2

You're not doing anything wrong. Apple is.

The println function is the problem, not string concatenation. This gives me the same error:

println(1 + 2 + 3 + 4 + 5 + 6)

You can work around it by declaring your own wrapper:

func myprint<T>(x: T) {
    println(x)
}

myprint(1 + 2 + 3 + 4 + 5 + 6)
myprint("1" + "2" + "3" + "4" + "5" + "6")
myprint("1" + "2" + "3" + "4" + "5" + "6" + "1" + "2" + "3" + "4" + "5" + "6")

Output:

21
123456
123456123456
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • I played a little bit with Xcode Beta 6.3. Looks like Apple fixed this issue :) – nemke Feb 11 '15 at 01:11
  • @nemke IMHO, the sands have merely shifted. It may have fixed some situations, but I have some expressions that are still "too complex" in 6.3 beta 3. I even have one expression that worked fine in Xcode 6.2, but I had to break it up because it is apparently "too complex" for 6.3. (Sigh.) – Rob Mar 17 '15 at 20:59