diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index ba8abf5..97ad461 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -2297,6 +2297,10 @@ mk_error({map_in_map_key, KeyType}) -> Msg = io_lib:format("Invalid key type\n~s\n", [pp_type(" ", KeyType)]), Cxt = "Map keys cannot contain other maps.\n", mk_t_err(pos(KeyType), Msg, Cxt); +mk_error({cannot_call_init_function, Ann}) -> + Msg = "The 'init' function is called exclusively by the create contract transaction\n" + "and cannot be called from the contract code.\n", + mk_t_err(pos(Ann), Msg); mk_error(Err) -> Msg = io_lib:format("Unknown error: ~p\n", [Err]), mk_t_err(pos(0, 0), Msg). diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index c2af334..7a8dd7d 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -477,6 +477,10 @@ failing_contracts() -> "Invalid key type\n" " lm\n" "Map keys cannot contain other maps.">>]} + , {"calling_init_function", + [<>]} ]. -define(Path(File), "code_errors/" ??File). diff --git a/test/contracts/calling_init_function.aes b/test/contracts/calling_init_function.aes new file mode 100644 index 0000000..0200b47 --- /dev/null +++ b/test/contracts/calling_init_function.aes @@ -0,0 +1,7 @@ +contract CallingInitFunction = + + type state = int * int + + entrypoint init() = (1, 2) + + entrypoint call_init() = init()