diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index acb9b8b..7c081f2 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -813,10 +813,8 @@ infer1(Env, [{namespace, Ann, Name, Code} | Rest], Acc, Options) -> {Env1, Code1} = infer_contract_top(push_scope(namespace, Name, Env), namespace, Code, Options), Namespace1 = {namespace, Ann, Name, Code1}, infer1(pop_scope(Env1), Rest, [Namespace1 | Acc], Options); -infer1(Env, [Using = {using, _, _} | Rest], Acc, Options) -> - infer1(check_usings(Env, [Using]), Rest, Acc, Options); infer1(Env, [Using = {using, _, _, _} | Rest], Acc, Options) -> - infer1(check_usings(Env, [Using]), Rest, Acc, Options); + infer1(check_usings(Env, Using), Rest, Acc, Options); infer1(Env, [{pragma, _, _} | Rest], Acc, Options) -> %% Pragmas are checked in check_modifiers infer1(Env, Rest, Acc, Options). @@ -873,7 +871,6 @@ infer_contract(Env0, What, Defs0, Options) -> ({letfun, _, _, _, _, _}) -> function; ({fun_clauses, _, _, _, _}) -> function; ({fun_decl, _, _, _}) -> prototype; - ({using, _, _}) -> using; ({using, _, _, _}) -> using; (_) -> unexpected end, @@ -1010,10 +1007,16 @@ check_typedef(Env, {variant_t, Cons}) -> check_usings(Env, []) -> Env; -check_usings(Env = #env{ used_namespaces = UsedNamespaces }, [{using, _, Con} | Rest]) -> - check_usings(Env#env{ used_namespaces = UsedNamespaces ++ [{qname(Con), none}] }, Rest); check_usings(Env = #env{ used_namespaces = UsedNamespaces }, [{using, _, Con, Alias} | Rest]) -> - check_usings(Env#env{ used_namespaces = UsedNamespaces ++ [{qname(Con), qname(Alias)}] }, Rest). + AliasName = case Alias of + none -> + none; + _ -> + qname(Alias) + end, + check_usings(Env#env{ used_namespaces = UsedNamespaces ++ [{qname(Con), AliasName}] }, Rest); +check_usings(Env, Using = {using, _, _, _}) -> + check_usings(Env, [Using]). check_unexpected(Xs) -> [ type_error(X) || X <- Xs ]. @@ -1044,8 +1047,6 @@ check_modifiers_(Env, [{namespace, _, _, Decls} | Rest]) -> check_modifiers_(Env, [{pragma, Ann, Pragma} | Rest]) -> check_pragma(Env, Ann, Pragma), check_modifiers_(Env, Rest); -check_modifiers_(Env, [{using, _, _} | Rest]) -> - check_modifiers_(Env, Rest); check_modifiers_(Env, [{using, _, _, _} | Rest]) -> check_modifiers_(Env, Rest); check_modifiers_(Env, [Decl | Rest]) -> @@ -1801,10 +1802,8 @@ infer_block(Env, _, [{letval, Attrs, Pattern, E}|Rest], BlockType) -> {'case', _, NewPattern, {typed, _, {block, _, NewRest}, _}} = infer_case(Env, Attrs, Pattern, PatType, {block, Attrs, Rest}, BlockType), [{letval, Attrs, NewPattern, NewE}|NewRest]; -infer_block(Env, Attrs, [Using = {using, _, _} | Rest], BlockType) -> - infer_block(check_usings(Env, [Using]), Attrs, Rest, BlockType); infer_block(Env, Attrs, [Using = {using, _, _, _} | Rest], BlockType) -> - infer_block(check_usings(Env, [Using]), Attrs, Rest, BlockType); + infer_block(check_usings(Env, Using), Attrs, Rest, BlockType); infer_block(Env, Attrs, [E|Rest], BlockType) -> [infer_expr(Env, E)|infer_block(Env, Attrs, Rest, BlockType)]. diff --git a/src/aeso_parser.erl b/src/aeso_parser.erl index 15ece13..b5fd8b9 100644 --- a/src/aeso_parser.erl +++ b/src/aeso_parser.erl @@ -140,7 +140,7 @@ using() -> ?RULE(keyword(using), con(), optional({keyword(as), con()}), using(get_ann(_1), _2, _3)). using(Ann, Con, none) -> - {using, Ann, Con}; + {using, Ann, Con, none}; using(Ann, Con, {ok, {_, Alias}}) -> {using, Ann, Con, Alias}. diff --git a/src/aeso_syntax.erl b/src/aeso_syntax.erl index 13f0930..5fb02bb 100644 --- a/src/aeso_syntax.erl +++ b/src/aeso_syntax.erl @@ -35,6 +35,8 @@ -type qcon() :: {qcon, ann(), [name()]}. -type tvar() :: {tvar, ann(), name()}. +-type namespace_alias() :: none | con(). + -type decl() :: {contract_main, ann(), con(), [decl()]} | {contract_child, ann(), con(), [decl()]} | {contract_interface, ann(), con(), [decl()]} @@ -44,7 +46,7 @@ | {type_def, ann(), id(), [tvar()], typedef()} | {fun_clauses, ann(), id(), type(), [letfun() | fundecl()]} | {block, ann(), [decl()]} - | using() + | {using, ann(), con(), namespace_alias()} | fundecl() | letfun() | letval(). % Only for error msgs @@ -53,9 +55,6 @@ -type pragma() :: {compiler, '==' | '<' | '>' | '=<' | '>=', compiler_version()}. --type using() :: {using, ann(), con()} - | {using, ann(), con(), con()}. - -type letval() :: {letval, ann(), pat(), expr()}. -type letfun() :: {letfun, ann(), id(), [pat()], type(), expr()}. -type fundecl() :: {fun_decl, ann(), id(), type()}.