Simple expressions that Swift thinks are too complex

Here's an example of an expression that the Swift compiler says is too complex to be solved in reasonable time (Xcode 7.0, OS X 10.10.5):

let intBinaryOpsDict: [String : (Int, Int) -> Int] = [
    "add" : (+),
    "sub" : (-),
    "mul" : (*),
    "div" : (/)
]


Commenting out one of the four dictionary elements will make it compile.

So it can manage three, but inferring the specific type of four overloaded operators is too much, even though the specific type of the operators is right there in the explicitly declared type of the Dictionary, ie its Value type: (Int, Int) -> Int.

( 22810685 )


Feel free to add other examples of such seemingly simple expressions for which the compiler will give the error message:

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

Replies

             venueInfo += item["name"] + "\t" + item["price"] + "\n"


Apparently 4 is too complicated already. Strangest thing is that the code will build sometimes, but fails at other times. I'm confused. Is there any alternative?

How `item` is declared?

This is ridiculous. We are still seeing this in 3.0 beta.. Am I the only one here who is shocked that Swift was allowed to reach even a 1.0 release with such a user-hostile "feature"? Apple please prioritize removing this error for anything short of a page of arithmetic, it is far more important than things like removing existing operators.

I submitted a bug report on this issue when Swift stopped being able to parse a simple one-line quadratic expression.

This was evcentually fixed, but for some weird reason, Apple has reinstituted this "feature".

This means that even very simple arithmetic expressions need to be broken down into teensy tiny little steps, which makes many common mathematical operations almost impossible to comprehend.


I can't help but get the feeling that Apple had originally intended for Swift to be an industrial-grade language that was intended for serious development, but is now re-targetting it to be a "first language", primarily targeted toward programming novices.

Here is another example that causes this error


var a = 5
var b = 8
var e = 12
var d = 33
var k = 100

-a + -b - -e + -d

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

-a + -b - -e + -d

~~~~~~~~^~~~

Original message deleted.


I've just seen your other thread with similar info as I've deleted.

It seems that it happened by accident, thanks for fixing it))

I submitted a bug report on this issue


Let's see what Apple will say