2
var ret = -100.0 + (2.0 * 1.3) + (3.0 * 4.0) + (0.2 * 2.0 * 2.0) + 0.1 * 2.0 * 3.0
//output: Cannot invoke '+' with an argument list of type '($T24, $T31)'

When I perform the operation above, error occurs, it's very strange! Is it too complex for swift to compute?

Teejay
  • 7,210
  • 10
  • 45
  • 76
larryhou
  • 725
  • 4
  • 14

1 Answers1

6

The full error message can be found in the Build log in the Report Navigator:

main.swift:15:66: error: cannot invoke '+' with an argument list of type '($T24, $T31)'
var ret = -100.0 + (2.0 * 1.3) + (3.0 * 4.0) + (0.2 * 2.0 * 2.0) + 0.1 * 2.0 * 3.0
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
main.swift:15:66: note: expression was too complex to be solved in reasonable time;
      consider breaking up the expression into distinct sub-expressions
var ret = -100.0 + (2.0 * 1.3) + (3.0 * 4.0) + (0.2 * 2.0 * 2.0) + 0.1 * 2.0 * 3.0
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

So yes, this expression is too complex for the current (beta 6) Swift compiler. I would suggest to file a bug report.

At present, the only workaround seems to be to split the expression in two parts, e.g.

var ret = -100.0 + (2.0 * 1.3) + (3.0 * 4.0)
ret += (0.2 * 2.0 * 2.0) + 0.1 * 2.0 * 3.0

Of course the parentheses are not necessary here, but removing them does not solve the problem with the original expression.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382