Currently, the (If ...) rule on the genesis block evaluates everything that is strictly not #0 to the true branch. This includes terms that cannot reduce any further, which can cause some very unexpected behaviour when comparing objects of different types.
For example, the following code:
fun (Test x) {
(Test x) = (If (== x #5) (Done 'yay') (Fail #0))
}
run {
ask test = (Call 'Test' [#4])
(Done test)
}
will silently fail. It will always evaluate to (Done 'yay') even though it clearly is not the intended semantics, because the following comparison (== {T1 #4} #5) gets stuck, and If evaluates that to true.
I do believe that we should change it match only on #0 and #1, in order to avoid javascript-esque errors like these. But I think that this raises a bigger question: what should be the norm/expected behaviour on treating stuck terms?
cc @steinerkelvin @developedby
Currently, the
(If ...)rule on the genesis block evaluates everything that is strictly not#0to the true branch. This includes terms that cannot reduce any further, which can cause some very unexpected behaviour when comparing objects of different types.For example, the following code:
will silently fail. It will always evaluate to
(Done 'yay')even though it clearly is not the intended semantics, because the following comparison(== {T1 #4} #5)gets stuck, andIfevaluates that to true.I do believe that we should change it match only on
#0and#1, in order to avoid javascript-esque errors like these. But I think that this raises a bigger question: what should be the norm/expected behaviour on treating stuck terms?cc @steinerkelvin @developedby