Fix #324: bug when compiling default init in the presence of child contracts

This commit is contained in:
Ulf Norell 2021-07-05 09:29:43 +02:00
parent 1975ccf804
commit d07b321b25
3 changed files with 12 additions and 2 deletions

View File

@ -330,10 +330,11 @@ to_fcode(Env, [{Contract, Attrs, Con = {con, _, Name}, Decls}|Rest])
case Contract =:= contract_interface of case Contract =:= contract_interface of
false -> false ->
#{ builtins := Builtins } = Env, #{ builtins := Builtins } = Env,
ConEnv = Env#{ context => {contract_def, Name}, ConEnv = maps:remove(state_layout,
Env#{ context => {contract_def, Name},
builtins => Builtins#{[Name, "state"] => {get_state, none}, builtins => Builtins#{[Name, "state"] => {get_state, none},
[Name, "put"] => {set_state, 1}, [Name, "put"] => {set_state, 1},
[Name, "Chain", "event"] => {chain_event, 1}} }, [Name, "Chain", "event"] => {chain_event, 1}} }),
#{ functions := PrevFuns } = ConEnv, #{ functions := PrevFuns } = ConEnv,
#{ functions := Funs } = Env1 = #{ functions := Funs } = Env1 =
decls_to_fcode(ConEnv, Decls), decls_to_fcode(ConEnv, Decls),

View File

@ -199,6 +199,7 @@ compilable_contracts() ->
"clone", "clone",
"clone_simple", "clone_simple",
"create", "create",
"child_contract_init_bug",
"test" % Custom general-purpose test file. Keep it last on the list. "test" % Custom general-purpose test file. Keep it last on the list.
]. ].

View File

@ -0,0 +1,8 @@
contract Identity =
record state = {foo: int, bar: string}
entrypoint init() = {foo = 0, bar = ""}
main contract IdentityService =
stateful entrypoint createNewIdentity() : Identity =
put(())
Chain.create()