Check that init doesn't read or write the state
This commit is contained in:
@@ -316,4 +316,17 @@ failing_contracts() ->
|
||||
<<"Cannot pass non-zero value argument 1000 (at line 48, column 55)\nin the definition of non-stateful function fail6.">>,
|
||||
<<"Cannot pass non-zero value argument 1000 (at line 49, column 54)\nin the definition of non-stateful function fail7.">>,
|
||||
<<"Cannot pass non-zero value argument 1000 (at line 52, column 17)\nin the definition of non-stateful function fail8.">>]}
|
||||
, {"bad_init_state_access",
|
||||
[<<"The init function should return the initial state as its result and cannot write the state,\n"
|
||||
"but it calls\n"
|
||||
" - set_state (at line 11, column 5), which calls\n"
|
||||
" - roundabout (at line 8, column 36), which calls\n"
|
||||
" - put (at line 7, column 37)">>,
|
||||
<<"The init function should return the initial state as its result and cannot read the state,\n"
|
||||
"but it calls\n"
|
||||
" - new_state (at line 12, column 5), which calls\n"
|
||||
" - state (at line 5, column 27)">>,
|
||||
<<"The init function should return the initial state as its result and cannot read the state,\n"
|
||||
"but it calls\n"
|
||||
" - state (at line 13, column 13)">>]}
|
||||
].
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
contract BadInit =
|
||||
|
||||
type state = int
|
||||
|
||||
function new_state(n) = state + n
|
||||
|
||||
stateful function roundabout(n) = put(n)
|
||||
stateful function set_state(n) = roundabout(n)
|
||||
|
||||
stateful function init() =
|
||||
set_state(4)
|
||||
new_state(0)
|
||||
state + state
|
||||
Reference in New Issue
Block a user