diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 92a9d10..379aa62 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -14,8 +14,13 @@ -export([ infer/1 , infer/2 + , unfold_types_in_type/2 , unfold_types_in_type/3 + , switch_scope/2 , pp_type/2 + , lookup_env1/4 + , name/1 + , qname/1 ]). -include("aeso_utils.hrl"). @@ -159,6 +164,10 @@ %% -- Environment manipulation ----------------------------------------------- +-spec switch_scope(qname(), env()) -> env(). +switch_scope(Scope, Env) -> + Env#env{namespace = Scope}. + -spec push_scope(namespace | contract, aeso_syntax:con(), env()) -> env(). push_scope(Kind, Con, Env) -> Ann = aeso_syntax:get_ann(Con), @@ -403,7 +412,7 @@ lookup_env(Env, Kind, Ann, Name) -> end end. --spec lookup_env1(env(), type | term, aeso_syntax:ann(), qname()) -> false | {qname(), fun_info()}. +-spec lookup_env1(env(), type | term, aeso_syntax:ann(), qname()) -> false | {qname(), fun_info() | type_info()}. lookup_env1(#env{ namespace = Current, used_namespaces = UsedNamespaces, scopes = Scopes }, Kind, Ann, QName) -> Qual = lists:droplast(QName), Name = lists:last(QName), @@ -1586,13 +1595,13 @@ app_t(Ann, Name, Args) -> {app_t, Ann, Name, Args}. lookup_name(Env, As, Name) -> lookup_name(Env, As, Name, []). -lookup_name(Env = #env{ namespace = NS, current_function = {id, _, Fun} = CurFn }, As, Id, Options) -> +lookup_name(Env = #env{ namespace = NS, current_function = CurFn }, As, Id, Options) -> case lookup_env(Env, term, As, qname(Id)) of false -> type_error({unbound_variable, Id}), {Id, fresh_uvar(As)}; {QId, {_, Ty}} -> - when_warning(warn_unused_variables, fun() -> used_variable(NS, Fun, QId) end), + when_warning(warn_unused_variables, fun() -> used_variable(NS, name(CurFn), QId) end), when_warning(warn_unused_functions, fun() -> register_function_call(NS ++ qname(CurFn), QId) end), Freshen = proplists:get_value(freshen, Options, false), @@ -1633,7 +1642,8 @@ check_stateful_named_arg(_, _, _) -> ok. check_entrypoints(Defs) -> [ ensure_first_order_entrypoint(LetFun) || LetFun <- Defs, - aeso_syntax:get_ann(entrypoint, LetFun, false) ]. + aeso_syntax:get_ann(entrypoint, LetFun, false), + get_option(allow_higher_order_entrypoints, false) =:= false ]. ensure_first_order_entrypoint({letfun, Ann, Id = {id, _, Name}, Args, Ret, _}) -> [ ensure_first_order(ArgType, {higher_order_entrypoint, AnnArg, Id, {argument, ArgId, ArgType}}) diff --git a/src/aeso_syntax.erl b/src/aeso_syntax.erl index fbf4a6b..c6c0c9d 100644 --- a/src/aeso_syntax.erl +++ b/src/aeso_syntax.erl @@ -26,7 +26,7 @@ -type ann_format() :: '?:' | hex | infix | prefix | elif. -type ann() :: [ {line, ann_line()} | {col, ann_col()} | {format, ann_format()} | {origin, ann_origin()} - | stateful | private | payable | main | interface]. + | stateful | private | payable | main | interface | entrypoint]. -type name() :: string(). -type id() :: {id, ann(), name()}. @@ -42,6 +42,7 @@ | {contract_child, ann(), con(), [con()], [decl()]} | {contract_interface, ann(), con(), [con()], [decl()]} | {namespace, ann(), con(), [decl()]} + | {include, ann(), {string, ann(), string()}} | {pragma, ann(), pragma()} | {type_decl, ann(), id(), [tvar()]} % Only for error msgs | {type_def, ann(), id(), [tvar()], typedef()}