Skip to content

Commit

Permalink
Add purity checks to the ternary expression (#778)
Browse files Browse the repository at this point in the history
* fix issue

* fix a few tests
  • Loading branch information
jcp19 authored Jul 3, 2024
1 parent 59fc2b5 commit b684ebc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ trait GhostExprTyping extends BaseTyping { this: TypeInfoImpl =>
// check that `cond` is of type bool
assignableTo.errors(exprType(cond), BooleanT)(expr) ++
// check that `thn` and `els` have a common type
mergeableTypes.errors(exprType(thn), exprType(els))(expr)
mergeableTypes.errors(exprType(thn), exprType(els))(expr) ++
// check that all subexpressions are pure.
isPureExpr(cond) ++ isWeaklyPureExpr(thn) ++ isWeaklyPureExpr(els)

case n@PForall(vars, triggers, body) =>
// check whether all triggers are valid and consistent
Expand Down
12 changes: 12 additions & 0 deletions src/test/resources/regressions/issues/000777-1.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package issue000777

ghost
requires i >= 0
decreases i
func h(i int) (res int) {
//:: ExpectedOutput(type_error)
return i == 0 ? 0 : h(i - 1)
}
16 changes: 16 additions & 0 deletions src/test/resources/regressions/issues/000777-2.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package issue000777

ghost
requires i > 0
decreases i
pure func h(i int) (res int)

ghost
requires 0 <= i
decreases
func test(i int) {
x := i == 0 ? 0 : h(i)
}

0 comments on commit b684ebc

Please sign in to comment.