pact icon indicating copy to clipboard operation
pact copied to clipboard

enforce-one: takes in list of any type and returns the first item in list

Open LindaOrtega opened this issue 6 years ago • 1 comments

enforce-one seems to allow for passing in a list of any types (i.e. [true, false], [3, 4]). When this occurs, it returns the first item of the list. See examples below.

pact> (enforce-one "some" [false, true])
false
pact> (enforce-one "some" [true, false])
true
pact> (enforce-one "some" [false, false])
false
pact> (enforce-one "some-error-message" ["true","false","false","false","false","false"])
"true"
pact> (enforce-one "some" [3, 4])
3

It seems that enforce-one should only accept a list of other enforce statements. Docs should be updated.

LindaOrtega avatar Aug 15 '19 19:08 LindaOrtega

I think the problem here is that the Pact type for enforce-one, [bool] -> bool, is simply wrong - it does not have enough data to tell people that the list of bool must be tests, otherwise it has suprising behavior. The solution to this would be to either document the spooky behavior entirely (which does not scale), or to write tx-failing enforcement types into the type system.

cc @slpopejoy

emilypi avatar Aug 15 '19 19:08 emilypi