限制表达式中的术语数量?

时间:2014-08-20 18:45:44

标签: compiler-errors swift

编辑:这被Apple确认为编译器错误。

下面的第一个if表达式(17个术语)编译,并产生预期结果(false)。 第二个if表达式(18个术语)失败,并显示错误消息:

  

无法调用' ||'使用类型'($ T106,$ T110)'。

的参数列表

除了额外的术语外,这两个表达式是相同的。

解决问题我没有问题,但我只是不明白它在抱怨什么。有人可以告诉我我犯的是什么愚蠢的错误吗?这里是温和,非常缺乏经验的编码员。

import Darwin

var a = -1
if
    a == 0 ||
        a == 1 ||
        a == 2 ||
        a == 3 ||
        a == 4 ||
        a == 5 ||
        a == 6 ||
        a == 7 ||
        a == 8 ||
        a == 9 ||
        a == 10 ||
        a == 11 ||
        a == 12 ||
        a == 13 ||
        a == 14 ||
        a == 15 ||
        a == 16 ||
        a == 17 { println("value was true") } else { println("value was false")}

if
    a == 0 ||
        a == 1 ||
        a == 2 ||
        a == 3 ||
        a == 4 ||
        a == 5 ||
        a == 6 ||
        a == 7 ||
        a == 8 ||
        a == 9 ||
        a == 10 ||
        a == 11 ||
        a == 12 ||
        a == 13 ||
        a == 14 ||
        a == 15 ||
        a == 16 ||
        a == 17 ||
        a == 18 { println("value was true") } else { println("value was false")}

1 个答案:

答案 0 :(得分:3)

虽然错误已经解决,但您可以使用:

switch a {
case 0...17:
    println("value was true")
default:
    println("value was false")
}