The code that you pasted has a few other issues, I'll assume it's a copy/paste error since the errors you are reporting are different, but here the fixed version:
object Test {
def test(a: Int): Int = ({
require(a > 0)
var sum = 0
var i = 0
while(i < a) {
sum = sum + i
i = i + 1
}
sum
}) ensuring(res => res == a*(a-1)/2)
}
Of note, you were using an assignment in the ensuring clause, and you should not use return
along with ensuring
as Scala would just shortcut the ensuring and directly return from the function. In general, don't use return
in Leon, and I'm going to also advise to not use return
with Scala in most cases. Also you had a(a-1)
which is not valid Scala code for a multiplication, you should have a*(a-1)
.
Now, about the --xlang
option for Leon online. The code you are trying to verify relies on imperative programming (vars and loops) and the support in Leon for imperative programming comes from a module called xlang
. Unfortunately, xlang
support was desactivated from Leon Online, as it behaves quite poorly with the synthesis features of Leon. We are working on improving the xlang
module so that it can be run along with the rest of the features of Leon. Hopefully this should happen eventually.
In the meantime, your only option, if you wish to verify programs using imperative features such as the above, is to run Leon from the command line with the --xlang
option:
./leon --xlang Test.scala
You can find some documentation on how to install Leon on your system here: https://leon.epfl.ch/doc/installation.html