flintrocks / flint

The Flint Programming Language for Smart Contracts
MIT License
2 stars 0 forks source link

Check valid external call exception handling #97

Closed Aurel300 closed 5 years ago

Aurel300 commented 5 years ago

(From #72)

Errors in external calls may be handled by the Flint programmer manually, using the call (default mode) together with a do ... catch block. As a consequence, a call should always occur within a do ... catch block (in the same function). Additionally, a call! should not occur within a do ... catch block, since it may be misleading as the do ... catch doesn't actually handle errors of a call!. if let ... = call? { ... } is allowed both inside and outside do ... catch blocks, since it handles its own errors unambiguously.

// valid code
if let x: Int = call? ext.someReturningFunc() { ... } else { ... }
do {
  call ext.someFunc()
  // call? can occur anywhere
  if let x: Int = call? ext.someReturningFunc() { ... } else { ... }
} catch is ExternalCallError { ... }
call! ext.someFunc() // call! can occur only outside of do ... catch

// invalid code:
do {
  call! ext.someFunc() // forced mode cannot occur inside of do ... catch
} catch is ExternalCallError { ... }
call ext.someFunc() // default mode cannot occur outside of do ... catch

Keep in mind that do ... catch blocks may be nested.

Some of this is handled in #98

ckamueller commented 5 years ago

Closed with #128