Swift compilation error - Expression was too complex to be solved in reasonable time
<p>I'm making a very simple calculator and I'm getting a really strange compile time error. I'm getting the following error in my <code>CalculatorBrain</code> class:</p>

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

<p>Here is the code that generated the error</p>

<pre><code>private var operations: Dictionary&lt;String, Operation&gt; = [
    "π" : .Constant(M_PI),
    "±" : .UnaryOperation({ -$0 }),
    "×" : .BinaryOperation({ $0 * $1 }),
    "÷" : .BinaryOperation({ $0 / $1 }),
    "+" : .BinaryOperation({ $0 + $1 }),
    "−" : .BinaryOperation({ $0 - $1 }),
    "=" : .Equals
]
</code></pre>

<p>The strange thing is that if I remove the following:</p>

<pre><code>"±" : .UnaryOperation({ -$0 })
"+" : .BinaryOperation({ $0 + $1 })
"−" : .BinaryOperation({ $0 - $1 })
</code></pre>

<p>The code compiles, otherwise it throws the error.</p>

<p>Another strange thing is that if I change those to:</p>

<pre><code>"±" : .UnaryOperation({ (op1: Double) -&gt; Double in return -op1 })
"+" : .BinaryOperation({ (op1: Double, op2: Double) -&gt; Double in return op1 + op2 })
"−" : .BinaryOperation({ (op1: Double, op2: Double) -&gt; Double in return op1 - op2 })
</code></pre>

<p>The code compiles and does not throw the error.</p>

<p>I'm kind of confused as to why it works when using the operators the <code>*</code> and <code>/</code> and not <code>-</code> and <code>+</code></p>

<p>Just in case you're wondering how <code>Operation</code> is implemented, here it is:</p>

<pre><code>private enum Operation {
    case Constant(Double)
    case UnaryOperation((Double) -&gt; Double)
    case BinaryOperation((Double, Double) -&gt; Double)
    case Equals
}
</code></pre>

<p>I'm using Swift version 2.2 on Xcode Version 7.3.1</p>