Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow interfaces with defined state type #507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}}
]}.
Expand Down
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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">>,
Expand Down
Binary file modified rebar3
Binary file not shown.
10 changes: 7 additions & 3 deletions src/aeso_ast_infer_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/aeso_compiler_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
].

Expand Down
7 changes: 7 additions & 0 deletions test/contracts/init_fun_interface.aes
Original file line number Diff line number Diff line change
@@ -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