Skip to content

Commit

Permalink
Require collections given to arg{min,max} to be non-empty
Browse files Browse the repository at this point in the history
This is additional progress on #23.
  • Loading branch information
Calvin-L committed Jul 10, 2018
1 parent b947c9e commit 40c7378
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cozy/invariant_preservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def check_the_wf(spec : Spec):
res.append("at {}: `the` is illegal since its argument may not be singleton".format(pprint(e)))
return res

def check_minmax_wf(spec : Spec):
res = []
for ctx in enumerate_fragments(spec):
e = ctx.e
if isinstance(e, EArgMin) or isinstance(e, EArgMax):
a = ctx.facts
if not valid(EImplies(EAll(a), EUnaryOp(UOp.Exists, e.e).with_type(BOOL))):
res.append("at {}: result is ambiguous since {} could be empty".format(pprint(e), pprint(e.e)))
return res

def check_calls_wf(spec : Spec):
res = []
queries = { m.name : m for m in spec.methods if isinstance(m, Query) }
Expand Down
1 change: 1 addition & 0 deletions cozy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def run():
errors = (
invariant_preservation.check_ops_preserve_invariants(ast) +
invariant_preservation.check_the_wf(ast) +
invariant_preservation.check_minmax_wf(ast) +
call_errors)
if errors:
for e in errors:
Expand Down

0 comments on commit 40c7378

Please sign in to comment.