Merge pull request #98 from aeternity/namespace-fix

Namespace fix
This commit is contained in:
Hans Svensson 2019-06-27 09:34:48 +02:00 committed by GitHub
commit c647a2cd34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

View File

@ -135,6 +135,10 @@ on_current_scope(Env = #env{ namespace = NS, scopes = Scopes }, Fun) ->
Scope = maps:get(NS, Scopes), Scope = maps:get(NS, Scopes),
Env#env{ scopes = Scopes#{ NS => Fun(Scope) } }. Env#env{ scopes = Scopes#{ NS => Fun(Scope) } }.
-spec on_scopes(env(), fun((scope()) -> scope())) -> env().
on_scopes(Env = #env{ namespace = NS, scopes = Scopes }, Fun) ->
Env#env{ scopes = maps:map(fun(_, Scope) -> Fun(Scope) end, Scopes) }.
-spec bind_var(aeso_syntax:id(), type(), env()) -> env(). -spec bind_var(aeso_syntax:id(), type(), env()) -> env().
bind_var({id, Ann, X}, T, Env) -> bind_var({id, Ann, X}, T, Env) ->
Env#env{ vars = [{X, {Ann, T}} | Env#env.vars] }. Env#env{ vars = [{X, {Ann, T}} | Env#env.vars] }.
@ -535,9 +539,15 @@ infer(Contracts, Options) ->
create_options(Options), create_options(Options),
ets_new(type_vars, [set]), ets_new(type_vars, [set]),
{Env1, Decls} = infer1(Env, Contracts, [], Options), {Env1, Decls} = infer1(Env, Contracts, [], Options),
{Env2, Decls2} =
case proplists:get_value(dont_unfold, Options, false) of
true -> {Env1, Decls};
false -> E = on_scopes(Env1, fun(Scope) -> unfold_record_types(Env1, Scope) end),
{E, unfold_record_types(E, Decls)}
end,
case proplists:get_value(return_env, Options, false) of case proplists:get_value(return_env, Options, false) of
false -> Decls; false -> Decls2;
true -> {Env1, Decls} true -> {Env2, Decls2}
end end
after after
clean_up_ets() clean_up_ets()
@ -571,14 +581,9 @@ check_scope_name_clash(Env, Kind, Name) ->
-spec infer_contract_top(env(), contract | namespace, [aeso_syntax:decl()], list(option())) -> -spec infer_contract_top(env(), contract | namespace, [aeso_syntax:decl()], list(option())) ->
{env(), [aeso_syntax:decl()]}. {env(), [aeso_syntax:decl()]}.
infer_contract_top(Env, Kind, Defs0, Options) -> infer_contract_top(Env, Kind, Defs0, _Options) ->
Defs = desugar(Defs0), Defs = desugar(Defs0),
{Env1, Defs1} = infer_contract(Env, Kind, Defs), infer_contract(Env, Kind, Defs).
case proplists:get_value(dont_unfold, Options, false) of
true -> {Env1, Defs1};
false -> Env2 = on_current_scope(Env1, fun(Scope) -> unfold_record_types(Env1, Scope) end),
{Env2, unfold_record_types(Env2, Defs1)}
end.
%% TODO: revisit %% TODO: revisit
infer_constant({letval, Attrs,_Pattern, Type, E}) -> infer_constant({letval, Attrs,_Pattern, Type, E}) ->
@ -2257,7 +2262,9 @@ pp({named_arg_t, _, Name, Type, Default}) ->
pp({fun_t, _, Named = {uvar, _, _}, As, B}) -> pp({fun_t, _, Named = {uvar, _, _}, As, B}) ->
["(", pp(Named), " | ", pp(As), ") => ", pp(B)]; ["(", pp(Named), " | ", pp(As), ") => ", pp(B)];
pp({fun_t, _, Named, As, B}) when is_list(Named) -> pp({fun_t, _, Named, As, B}) when is_list(Named) ->
["(", pp(Named ++ As), ") => ", pp(B)]. ["(", pp(Named ++ As), ") => ", pp(B)];
pp(Other) ->
io_lib:format("~p", [Other]).
%% -- Pre-type checking desugaring ------------------------------------------- %% -- Pre-type checking desugaring -------------------------------------------

View File

@ -8,5 +8,11 @@ namespace Foo =
contract Bug = contract Bug =
// Crashed the type checker // Crashed the type checker
function foo () = Foo.bar() function foo() = Foo.bar()
// Also crashed the type checker
type t = Foo.bla
function test() =
let x : t = Foo.bar()
x