From 67496010d59a7c33cd3258766d2a9b2980ed630c Mon Sep 17 00:00:00 2001 From: radrow Date: Mon, 23 Mar 2020 18:04:33 +0100 Subject: [PATCH] Fix prettpr attr display. Make dialyzer happy --- src/aeso_ast_infer_types.erl | 6 ++++-- src/aeso_pretty.erl | 21 +++++++++++++-------- test/contracts/all_syntax.aes | 26 +++++++++++++------------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 6620381..676814d 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -2275,8 +2275,10 @@ mk_error({wrong_type_arguments, X, ArityGiven, ArityReal}) -> mk_error({unnamed_map_update_with_default, Upd}) -> Msg = "Invalid map update with default\n", mk_t_err(pos(Upd), Msg); -mk_error({fundecl_must_have_funtype, _Ann, Id, _Type}) -> - Msg = io_lib:format("Function/entrypoint declaration must have a function type\n"), +mk_error({fundecl_must_have_funtype, _Ann, Id, Type}) -> + Msg = io_lib:format("~s at ~s was declared with an invalid type ~s.\n" + "Entrypoints and functions must have functional types" + , [pp(Id), pp_loc(Id), pp(instantiate(Type))]), mk_t_err(pos(Id), Msg); mk_error({cannot_unify, A, B, When}) -> Msg = io_lib:format("Cannot unify ~s\n and ~s\n", diff --git a/src/aeso_pretty.erl b/src/aeso_pretty.erl index bf00107..ac80edb 100644 --- a/src/aeso_pretty.erl +++ b/src/aeso_pretty.erl @@ -145,8 +145,12 @@ decl(D, Options) -> with_options(Options, fun() -> decl(D) end). -spec decl(aeso_syntax:decl()) -> doc(). -decl({contract, _, C, Ds}) -> - block(follow(text("contract"), hsep(name(C), text("="))), decls(Ds)); +decl({contract, Attrs, C, Ds}) -> + Mod = fun({Mod, true}) when Mod == payable -> + text(atom_to_list(Mod)); + (_) -> empty() end, + block(follow( hsep(lists:map(Mod, Attrs) ++ [text("contract")]) + , hsep(name(C), text("="))), decls(Ds)); decl({namespace, _, C, Ds}) -> block(follow(text("namespace"), hsep(name(C), text("="))), decls(Ds)); decl({pragma, _, Pragma}) -> pragma(Pragma); @@ -155,13 +159,16 @@ decl({type_def, _, T, Vars, Def}) -> Kind = element(1, Def), equals(typedecl(Kind, T, Vars), typedef(Def)); decl({fun_decl, Ann, F, T}) -> + Mod = fun({Mod, true}) when Mod == private; Mod == stateful; Mod == payable -> + text(atom_to_list(Mod)); + (_) -> empty() end, Fun = case aeso_syntax:get_ann(entrypoint, Ann, false) of true -> text("entrypoint"); false -> text("function") end, - hsep(Fun, typed(name(F), T)); + hsep(lists:map(Mod, Ann) ++ [Fun, typed(name(F), T)]); decl(D = {letfun, Attrs, _, _, _, _}) -> - Mod = fun({Mod, true}) when Mod == private; Mod == stateful -> + Mod = fun({Mod, true}) when Mod == private; Mod == stateful; Mod == payable -> text(atom_to_list(Mod)); (_) -> empty() end, Fun = case aeso_syntax:get_ann(entrypoint, Attrs, false) of @@ -364,7 +371,8 @@ expr_p(_, {Type, _, Bin}) Type == oracle_query_id -> text(binary_to_list(aeser_api_encoder:encode(Type, Bin))); expr_p(_, {string, _, <<>>}) -> text("\"\""); -expr_p(_, {string, _, S}) -> term(binary_to_list(S)); +expr_p(_, {string, _, S}) -> + text(io_lib:format("\"~s\"", [binary_to_list(S)])); expr_p(_, {char, _, C}) -> case C of $' -> text("'\\''"); @@ -486,6 +494,3 @@ get_elifs(If = {'if', Ann, Cond, Then, Else}, Elifs) -> end; get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}. -fmt(Fmt, Args) -> text(lists:flatten(io_lib:format(Fmt, Args))). -term(X) -> fmt("~p", [X]). - diff --git a/test/contracts/all_syntax.aes b/test/contracts/all_syntax.aes index 26e3ab3..6a40f27 100644 --- a/test/contracts/all_syntax.aes +++ b/test/contracts/all_syntax.aes @@ -2,23 +2,22 @@ @compiler > 0 @compiler =< 10.1.1.1.1.1.2.3.4 -contract AllSyntaxType = + +namespace Ns = + datatype d('a) = D | S(int) | M('a, list('a), int) + private function fff() = 123 + + stateful entrypoint + f (1, x) = (_) => x + +payable contract AllSyntaxType = /** Multi- * line * comment */ - function foo : _ + stateful function foo : _ entrypoint bar : int => (int * 'a) -/* -namespace Ns = - datatype d('a) = D | S(int) | M('a, list('a), int) - private function f() = 123 - entrypoint - f : (int, 'a) => ('a * 'b) => 'a - f (1, x) = (_) => x - f (_, _) = (t : 'a * 'b) => switch(t) - (l, r) => l - _ => abort("tuple exploit") + contract AllSyntax = @@ -47,6 +46,7 @@ contract AllSyntax = goethe = () } function f() = + let kp = "nietzsche" let p = "Пушкин" let k(x : bytes(8)) : bytes(8) = Bytes.to_int(#fedcba9876543210) @@ -68,6 +68,7 @@ contract AllSyntax = _ => 13 1::[2] => 2138 put(state{johann = 1}) + let m = {["foo"] = 19, /*hey wanna talk about inlined comments?*/ ["bar"] = 42} let n = {} m{ ["x" = 0] @ z = z + state.johann } @@ -75,4 +76,3 @@ contract AllSyntax = let sh : shakespeare(shakespeare(int)) = {wolfgang = state} sh{wolfgang.wolfgang = sh.wolfgang} // comment -/* \ No newline at end of file