Move error reporting to aeso_tc_env
This commit is contained in:
parent
de4c8f5412
commit
ac428d1e36
@ -51,7 +51,7 @@ set_qname(A, B) -> aeso_tc_name_manip:set_qname(A, B).
|
|||||||
|
|
||||||
type_error(A) -> aeso_tc_errors:type_error(A).
|
type_error(A) -> aeso_tc_errors:type_error(A).
|
||||||
create_type_errors() -> aeso_tc_errors:create_type_errors().
|
create_type_errors() -> aeso_tc_errors:create_type_errors().
|
||||||
destroy_and_report_type_errors(A) -> aeso_tc_errors:destroy_and_report_type_errors(A).
|
destroy_and_report_type_errors(A) -> aeso_tc_env:destroy_and_report_type_errors(A).
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
|
|
||||||
|
@ -68,6 +68,8 @@
|
|||||||
, empty_env/0
|
, empty_env/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-export([destroy_and_report_type_errors/1]).
|
||||||
|
|
||||||
-export_type([env/0]).
|
-export_type([env/0]).
|
||||||
|
|
||||||
-include("aeso_utils.hrl").
|
-include("aeso_utils.hrl").
|
||||||
@ -147,6 +149,7 @@ infer_const(A, B) -> aeso_ast_infer_types:infer_const(A, B).
|
|||||||
name(A) -> aeso_tc_name_manip:name(A).
|
name(A) -> aeso_tc_name_manip:name(A).
|
||||||
qname(A) -> aeso_tc_name_manip:qname(A).
|
qname(A) -> aeso_tc_name_manip:qname(A).
|
||||||
qid(A, B) -> aeso_tc_name_manip:qid(A, B).
|
qid(A, B) -> aeso_tc_name_manip:qid(A, B).
|
||||||
|
qcon(A, B) -> aeso_tc_name_manip:qcon(A, B).
|
||||||
set_qname(A, B) -> aeso_tc_name_manip:set_qname(A, B).
|
set_qname(A, B) -> aeso_tc_name_manip:set_qname(A, B).
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
@ -992,3 +995,27 @@ global_env() ->
|
|||||||
maps:from_list([{N, [#field_info{ ann = [], field_t = T, record_t = Tx, kind = record }]}
|
maps:from_list([{N, [#field_info{ ann = [], field_t = T, record_t = Tx, kind = record }]}
|
||||||
|| {N, T} <- TxFlds ])
|
|| {N, T} <- TxFlds ])
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
destroy_and_report_type_errors(Env) ->
|
||||||
|
Errors0 = lists:reverse(aeso_tc_ets_manager:ets_tab2list(type_errors)),
|
||||||
|
%% io:format("Type errors now: ~p\n", [Errors0]),
|
||||||
|
aeso_tc_errors:destroy_type_errors(),
|
||||||
|
Errors = [ aeso_tc_errors:mk_error(unqualify(Env, Err)) || Err <- Errors0 ],
|
||||||
|
aeso_errors:throw(Errors). %% No-op if Errors == []
|
||||||
|
|
||||||
|
%% Strip current namespace from error message for nicer printing.
|
||||||
|
unqualify(Env, {qid, Ann, Xs}) ->
|
||||||
|
qid(Ann, unqualify1(aeso_tc_env:namespace(Env), Xs));
|
||||||
|
unqualify(Env, {qcon, Ann, Xs}) ->
|
||||||
|
qcon(Ann, unqualify1(aeso_tc_env:namespace(Env), Xs));
|
||||||
|
unqualify(Env, T) when is_tuple(T) ->
|
||||||
|
list_to_tuple(unqualify(Env, tuple_to_list(T)));
|
||||||
|
unqualify(Env, [H | T]) -> [unqualify(Env, H) | unqualify(Env, T)];
|
||||||
|
unqualify(_Env, X) -> X.
|
||||||
|
|
||||||
|
unqualify1(NS, Xs) ->
|
||||||
|
try lists:split(length(NS), Xs) of
|
||||||
|
{NS, Ys} -> Ys;
|
||||||
|
_ -> Xs
|
||||||
|
catch _:_ -> Xs
|
||||||
|
end.
|
||||||
|
@ -5,14 +5,13 @@
|
|||||||
-export([cannot_unify/4
|
-export([cannot_unify/4
|
||||||
, type_error/1
|
, type_error/1
|
||||||
, create_type_errors/0
|
, create_type_errors/0
|
||||||
, destroy_and_report_type_errors/1
|
, destroy_type_errors/0
|
||||||
|
, mk_error/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% -- Moved functions --------------------------------------------------------
|
%% -- Moved functions --------------------------------------------------------
|
||||||
|
|
||||||
name(A) -> aeso_tc_name_manip:name(A).
|
name(A) -> aeso_tc_name_manip:name(A).
|
||||||
qid(A, B) -> aeso_tc_name_manip:qid(A, B).
|
|
||||||
qcon(A, B) -> aeso_tc_name_manip:qcon(A, B).
|
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
|
|
||||||
@ -42,29 +41,8 @@ type_error(Err) ->
|
|||||||
create_type_errors() ->
|
create_type_errors() ->
|
||||||
aeso_tc_ets_manager:ets_new(type_errors, [bag]).
|
aeso_tc_ets_manager:ets_new(type_errors, [bag]).
|
||||||
|
|
||||||
destroy_and_report_type_errors(Env) ->
|
destroy_type_errors() ->
|
||||||
Errors0 = lists:reverse(aeso_tc_ets_manager:ets_tab2list(type_errors)),
|
aeso_tc_ets_manager:ets_delete(type_errors).
|
||||||
%% io:format("Type errors now: ~p\n", [Errors0]),
|
|
||||||
aeso_tc_ets_manager:ets_delete(type_errors),
|
|
||||||
Errors = [ mk_error(unqualify(Env, Err)) || Err <- Errors0 ],
|
|
||||||
aeso_errors:throw(Errors). %% No-op if Errors == []
|
|
||||||
|
|
||||||
%% Strip current namespace from error message for nicer printing.
|
|
||||||
unqualify(Env, {qid, Ann, Xs}) ->
|
|
||||||
qid(Ann, unqualify1(aeso_tc_env:namespace(Env), Xs));
|
|
||||||
unqualify(Env, {qcon, Ann, Xs}) ->
|
|
||||||
qcon(Ann, unqualify1(aeso_tc_env:namespace(Env), Xs));
|
|
||||||
unqualify(Env, T) when is_tuple(T) ->
|
|
||||||
list_to_tuple(unqualify(Env, tuple_to_list(T)));
|
|
||||||
unqualify(Env, [H | T]) -> [unqualify(Env, H) | unqualify(Env, T)];
|
|
||||||
unqualify(_Env, X) -> X.
|
|
||||||
|
|
||||||
unqualify1(NS, Xs) ->
|
|
||||||
try lists:split(length(NS), Xs) of
|
|
||||||
{NS, Ys} -> Ys;
|
|
||||||
_ -> Xs
|
|
||||||
catch _:_ -> Xs
|
|
||||||
end.
|
|
||||||
|
|
||||||
mk_t_err(Pos, Msg) ->
|
mk_t_err(Pos, Msg) ->
|
||||||
aeso_errors:new(type_error, Pos, lists:flatten(Msg)).
|
aeso_errors:new(type_error, Pos, lists:flatten(Msg)).
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
type_error(A) -> aeso_tc_errors:type_error(A).
|
type_error(A) -> aeso_tc_errors:type_error(A).
|
||||||
create_type_errors() -> aeso_tc_errors:create_type_errors().
|
create_type_errors() -> aeso_tc_errors:create_type_errors().
|
||||||
destroy_and_report_type_errors(A) -> aeso_tc_errors:destroy_and_report_type_errors(A).
|
destroy_and_report_type_errors(A) -> aeso_tc_env:destroy_and_report_type_errors(A).
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user