Allow self-qualification (#503)

* Properly allow self-qualification

* Changelog

* Simplify logic as suggested by Ulf
This commit is contained in:
Hans Svensson 2024-02-16 09:56:26 +01:00 committed by GitHub
parent 1387e814f8
commit 944ed49f0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
### Removed ### Removed
### Fixed ### Fixed
- Allow self-qualification, i.e. referencing `X.foo` when in namespace `X`.
## [8.0.0-rc1] ## [8.0.0-rc1]
### Added ### Added

View File

@ -1161,7 +1161,7 @@ infer_contract(Env0, What, Defs0, Options) ->
_ = bind_funs(lists:map(FunBind, Functions), #env{}), _ = bind_funs(lists:map(FunBind, Functions), #env{}),
FunMap = maps:from_list([ {FunName(Def), Def} || Def <- Functions ]), FunMap = maps:from_list([ {FunName(Def), Def} || Def <- Functions ]),
check_reserved_entrypoints(FunMap), check_reserved_entrypoints(FunMap),
DepGraph = maps:map(fun(_, Def) -> aeso_syntax_utils:used_ids(Def) end, FunMap), DepGraph = maps:map(fun(_, Def) -> aeso_syntax_utils:used_ids(Env3#env.namespace, Def) end, FunMap),
SCCs = aeso_utils:scc(DepGraph), SCCs = aeso_utils:scc(DepGraph),
{Env4, Defs1} = check_sccs(Env3, FunMap, SCCs, []), {Env4, Defs1} = check_sccs(Env3, FunMap, SCCs, []),
%% Remove namespaces used in the current namespace %% Remove namespaces used in the current namespace
@ -2953,7 +2953,6 @@ record_type_name({app_t, _Attrs, RecId, _Args}) when ?is_type_id(RecId) ->
record_type_name(RecId) when ?is_type_id(RecId) -> record_type_name(RecId) when ?is_type_id(RecId) ->
RecId; RecId;
record_type_name(_Other) -> record_type_name(_Other) ->
%% io:format("~p is not a record type\n", [Other]),
{id, [{origin, system}], "not_a_record_type"}. {id, [{origin, system}], "not_a_record_type"}.
solve_for_uvar(Env, UVar = {uvar, Attrs, _}, Fields0) -> solve_for_uvar(Env, UVar = {uvar, Attrs, _}, Fields0) ->
@ -3562,7 +3561,6 @@ create_type_errors() ->
destroy_and_report_type_errors(Env) -> destroy_and_report_type_errors(Env) ->
Errors0 = lists:reverse(ets_tab2list(type_errors)), Errors0 = lists:reverse(ets_tab2list(type_errors)),
%% io:format("Type errors now: ~p\n", [Errors0]),
ets_delete(type_errors), ets_delete(type_errors),
Errors = [ mk_error(unqualify(Env, Err)) || Err <- Errors0 ], Errors = [ mk_error(unqualify(Env, Err)) || Err <- Errors0 ],
aeso_errors:throw(Errors). %% No-op if Errors == [] aeso_errors:throw(Errors). %% No-op if Errors == []

View File

@ -6,7 +6,7 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(aeso_syntax_utils). -module(aeso_syntax_utils).
-export([used_ids/1, used_types/2, used/1]). -export([used_ids/1, used_ids/2, used_types/2, used/1]).
-record(alg, {zero, plus, scoped}). -record(alg, {zero, plus, scoped}).
@ -110,8 +110,16 @@ fold(Alg = #alg{zero = Zero, plus = Plus, scoped = Scoped}, Fun, K, X) ->
%% Name dependencies %% Name dependencies
%% Used ids, top level
used_ids(E) -> used_ids(E) ->
[ X || {{term, [X]}, _} <- used(E) ]. used_ids([], E).
%% Used ids, top level or in (current) namespace
used_ids(Ns, E) ->
[ lists:last(Xs) || {{term, Xs}, _} <- used(E), in_ns(Xs, Ns) ].
in_ns([_], _) -> true;
in_ns(Xs, Ns) -> lists:droplast(Xs) == Ns.
used_types([Top] = _CurrentNS, T) -> used_types([Top] = _CurrentNS, T) ->
F = fun({{type, [X]}, _}) -> [X]; F = fun({{type, [X]}, _}) -> [X];