clarity-lang / reference

The Clarity Reference
146 stars 34 forks source link

Assert to check invariants and abort contract call #26

Open njordhov opened 4 years ago

njordhov commented 4 years ago

Clarity should have an assert construct that aborts the contract call when an invariant predicate is false.

Assertions are common in programming languages, including other Lisp dialects: Clojure has assert; Common Lisp has assert; Scheme has assert; Typed Racket has with-asserts;

Clarity already have an asserts! form, but instead of aborting the contract call, it returns an error from the current function. This is a foot gun for Clarity developers, inviting security flaws such as failing to handle severe errors. It is also inflexible, limiting assertions to functions that return a result type.

friedger commented 4 years ago

It could be named asserts-panic, or asserts-abort as proposed in #25

njordhov commented 4 years ago

It could be named asserts-panic, or asserts-abort

Extra verbosity not required as just assert is widely recognized for this functionality.