diff --git a/rebar.config b/rebar.config index f9f611f0..b9d754a7 100644 --- a/rebar.config +++ b/rebar.config @@ -2,7 +2,7 @@ {erl_opts, [debug_info]}. -{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {tag, "v3.4.0"}}} +{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {tag, "v3.4.1"}}} , {eblake2, "1.0.0"} , {jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}} ]}. diff --git a/rebar.lock b/rebar.lock index 58ce514d..8a19f04a 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,11 +1,11 @@ {"1.2.0", [{<<"aebytecode">>, {git,"https://github.com/aeternity/aebytecode.git", - {ref,"009e0361922037f978f9c0ef357d4d1be8559928"}}, + {ref,"6bd6f82c70d800950ea1a2c70c364a4181ff5291"}}, 0}, {<<"aeserialization">>, {git,"https://github.com/aeternity/aeserialization.git", - {ref,"177bf604b2a05e940f92cf00e96e6e269e708245"}}, + {ref,"b26e6d105424748ba1c27917267b7cff07f37802"}}, 1}, {<<"base58">>, {git,"https://github.com/aeternity/erl-base58.git", @@ -14,7 +14,7 @@ {<<"eblake2">>,{pkg,<<"eblake2">>,<<"1.0.0">>},0}, {<<"enacl">>, {git,"https://github.com/aeternity/enacl.git", - {ref,"793ddb502f7fe081302e1c42227dca70b09f8e17"}}, + {ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}, 2}, {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},1}, {<<"jsx">>, diff --git a/rebar3 b/rebar3 index a83d554a..bf217085 100755 Binary files a/rebar3 and b/rebar3 differ diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index b78ea380..edf6c32e 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -1167,7 +1167,7 @@ infer_contract(Env0, What, Defs0, Options) -> %% Remove namespaces used in the current namespace Env5 = Env4#env{ used_namespaces = OldUsedNamespaces }, %% Check that `init` doesn't read or write the state and that `init` is not missing - check_state(Env4, Defs1), + check_state(Env4, Defs1, Decls, What), %% Check that entrypoints have first-order arg types and return types check_entrypoints(Defs1), destroy_and_report_type_errors(Env4), @@ -1881,13 +1881,17 @@ check_state_init(Env) -> %% Check that `init` doesn't read or write the state and that `init` is defined %% when the state type is not unit -check_state(Env, Defs) -> +check_state(Env, Defs, Decls, What) -> Top = Env#env.namespace, GetState = Top ++ ["state"], SetState = Top ++ ["put"], Init = Top ++ ["init"], UsedNames = fun(X) -> [{Xs, Ann} || {{term, Xs}, Ann} <- aeso_syntax_utils:used(X)] end, - Funs = [ {Top ++ [Name], Fun} || Fun = {letfun, _, {id, _, Name}, _Args, _Type, _GuardedBodies} <- Defs ], + Funs = case What of + contract -> [ {Top ++ [Name], Fun} || Fun = {letfun, _, {id, _, Name}, _Args, _Type, _GuardedBodies} <- Defs ]; + contract_interface -> [ {Top ++ [Name], Fun} || Fun = {fun_decl, _, {id, _, Name}, _Type} <- Decls ]; + namespace -> [] + end, Deps = maps:from_list([{Name, UsedNames(Def)} || {Name, Def} <- Funs]), case maps:get(Init, Deps, false) of false -> get_option(no_code, false) orelse check_state_init(Env); diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index 3bd922d6..d2a522f0 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -227,6 +227,7 @@ compilable_contracts() -> "resolve_field_constraint_by_arity", "toplevel_constants", "ceres", + "init_fun_interface", "test" % Custom general-purpose test file. Keep it last on the list. ]. diff --git a/test/contracts/init_fun_interface.aes b/test/contracts/init_fun_interface.aes new file mode 100644 index 00000000..3055303f --- /dev/null +++ b/test/contracts/init_fun_interface.aes @@ -0,0 +1,7 @@ +contract interface I = + record state = { x : int } + entrypoint f : () => state + entrypoint init : () => state + +main contract C = + entrypoint g(c : I) : int = c.f().x