From 0a4c49215e352595dd9cabd9f1a192159405004d Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Tue, 1 Feb 2022 19:37:16 +0400 Subject: [PATCH] Return warnings as a sorted list --- src/aeso_ast_infer_types.erl | 3 ++- src/aeso_warnings.erl | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 3ce4836..2324547 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -826,7 +826,8 @@ infer(Contracts, Options) -> {Env1, Decls} = infer1(Env, Contracts1, [], Options), when_warning(warn_unused_functions, fun() -> destroy_and_report_unused_functions() end), when_option(warn_error, fun() -> destroy_and_report_warnings_as_type_errors() end), - Warnings = lists:map(fun mk_warning/1, ets_tab2list(warnings)), + WarningsUnsorted = lists:map(fun mk_warning/1, ets_tab2list(warnings)), + Warnings = aeso_warnings:sort_warnings(WarningsUnsorted), {Env2, DeclsFolded, DeclsUnfolded} = case proplists:get_value(dont_unfold, Options, false) of true -> {Env1, Decls, Decls}; diff --git a/src/aeso_warnings.erl b/src/aeso_warnings.erl index bf16edf..47daeae 100644 --- a/src/aeso_warnings.erl +++ b/src/aeso_warnings.erl @@ -11,6 +11,7 @@ -export([ new/1 , new/2 , warn_to_err/2 + , sort_warnings/1 , pp/1 ]). @@ -23,5 +24,8 @@ new(Pos, Msg) -> warn_to_err(Kind, #warn{ pos = Pos, message = Msg }) -> aeso_errors:new(Kind, Pos, lists:flatten(Msg)). +sort_warnings(Warnings) -> + lists:sort(fun(W1, W2) -> W1#warn.pos =< W2#warn.pos end, Warnings). + pp(#warn{ pos = Pos, message = Msg }) -> lists:flatten(io_lib:format("Warning~s:\n~s", [aeso_errors:pp_pos(Pos), Msg])).