Closed jcp19 closed 3 months ago
Alternatively, we could encode an impure ternary operator as an if statement. While convenient to overcome Go‘s shortage of a ternary operator, this encoding might be more surprising than just rejecting such ternary operators
Alternatively, we could encode an impure ternary operator as an if statement. While convenient to overcome Go‘s shortage of a ternary operator, this encoding might be more surprising than just rejecting such ternary operators
Yeah, I think that would be too surprising, and I don't see a good reason for doing that transformation because a ghost if
is always acceptable in the contexts where a non-pure conditional expression was accepted before this PR.
Reported by Conradin Laux.
In the file below, function
h2
verifies just fine, but functionh
does not, even though it computes the same value ash2
using a ternary expression.Looking at the viper encoding, we find that the ternary expression in function
h
is encoded asClearly, this is wrong. I think that the most appropriate solution here is to always require that a ternary expression is pure. As such, the example above would be rejected because we would call a non-pure function in a ternary operation. This does not limit expressiveness, because we could always use a ghost if instead.