If I pretty-print an expression that indexes a sequence, where the sequence is not a simple expression, the requires parentheses around the sequence disappear:
function concatFirst(xs: Seq[Int], ys: Seq[Int]): Int {
(xs ++ ys)[0]
}
when parsed and pretty-printed (with viper.silver.ast.Node.toString) turns into:
function concatFirst(xs: Seq[Int], ys: Seq[Int]): Int
{
xs ++ ys[0]
}
We (the VerCors team) use pretty printing to diagnose the output of VerCors in vscode quite often, so it would be nice if this can be fixed. Thanks!
Here is the code I used to parse+print the example for completeness sake
package viper.api
import viper.silver.frontend.{SilFrontend, SilFrontendConfig}
import viper.silver.verifier.{NoVerifier, Verifier}
import java.io.{File, FileOutputStream, OutputStreamWriter}
object EmptyFrontend extends SilFrontend() {
val NO_VERIFIER = new NoVerifier
override def createVerifier(fullCmd: String): Verifier = NO_VERIFIER
override def configureVerifier(args: Seq[String]): SilFrontendConfig = ???
}
object TestSubscriptBug {
def main(args: Array[String]): Unit = {
val tmp = File.createTempFile("vercors-output-", ".sil")
tmp.deleteOnExit()
val writer = new OutputStreamWriter(new FileOutputStream(tmp))
writer.write("""function concatFirst(xs: Seq[Int], ys: Seq[Int]): Int { (xs ++ ys)[0] }""")
writer.close()
val frontend = EmptyFrontend
frontend.init(EmptyFrontend.NO_VERIFIER)
frontend.reset(tmp.toPath)
frontend.parsing()
frontend.semanticAnalysis()
frontend.translation()
assert(frontend.errors.isEmpty)
println(frontend.translationResult.toString())
}
}
If I pretty-print an expression that indexes a sequence, where the sequence is not a simple expression, the requires parentheses around the sequence disappear:
when parsed and pretty-printed (with
viper.silver.ast.Node.toString) turns into:We (the VerCors team) use pretty printing to diagnose the output of VerCors in vscode quite often, so it would be nice if this can be fixed. Thanks!
Here is the code I used to parse+print the example for completeness sake