Fix prettpr attr display. Make dialyzer happy

This commit is contained in:
radrow 2020-03-23 18:04:33 +01:00
parent da44338685
commit 67496010d5
3 changed files with 30 additions and 23 deletions

View File

@ -2275,8 +2275,10 @@ mk_error({wrong_type_arguments, X, ArityGiven, ArityReal}) ->
mk_error({unnamed_map_update_with_default, Upd}) -> mk_error({unnamed_map_update_with_default, Upd}) ->
Msg = "Invalid map update with default\n", Msg = "Invalid map update with default\n",
mk_t_err(pos(Upd), Msg); mk_t_err(pos(Upd), Msg);
mk_error({fundecl_must_have_funtype, _Ann, Id, _Type}) -> mk_error({fundecl_must_have_funtype, _Ann, Id, Type}) ->
Msg = io_lib:format("Function/entrypoint declaration must have a function type\n"), 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_t_err(pos(Id), Msg);
mk_error({cannot_unify, A, B, When}) -> mk_error({cannot_unify, A, B, When}) ->
Msg = io_lib:format("Cannot unify ~s\n and ~s\n", Msg = io_lib:format("Cannot unify ~s\n and ~s\n",

View File

@ -145,8 +145,12 @@ decl(D, Options) ->
with_options(Options, fun() -> decl(D) end). with_options(Options, fun() -> decl(D) end).
-spec decl(aeso_syntax:decl()) -> doc(). -spec decl(aeso_syntax:decl()) -> doc().
decl({contract, _, C, Ds}) -> decl({contract, Attrs, C, Ds}) ->
block(follow(text("contract"), hsep(name(C), text("="))), decls(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}) -> decl({namespace, _, C, Ds}) ->
block(follow(text("namespace"), hsep(name(C), text("="))), decls(Ds)); block(follow(text("namespace"), hsep(name(C), text("="))), decls(Ds));
decl({pragma, _, Pragma}) -> pragma(Pragma); decl({pragma, _, Pragma}) -> pragma(Pragma);
@ -155,13 +159,16 @@ decl({type_def, _, T, Vars, Def}) ->
Kind = element(1, Def), Kind = element(1, Def),
equals(typedecl(Kind, T, Vars), typedef(Def)); equals(typedecl(Kind, T, Vars), typedef(Def));
decl({fun_decl, Ann, F, T}) -> 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 Fun = case aeso_syntax:get_ann(entrypoint, Ann, false) of
true -> text("entrypoint"); true -> text("entrypoint");
false -> text("function") false -> text("function")
end, end,
hsep(Fun, typed(name(F), T)); hsep(lists:map(Mod, Ann) ++ [Fun, typed(name(F), T)]);
decl(D = {letfun, Attrs, _, _, _, _}) -> 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)); text(atom_to_list(Mod));
(_) -> empty() end, (_) -> empty() end,
Fun = case aeso_syntax:get_ann(entrypoint, Attrs, false) of Fun = case aeso_syntax:get_ann(entrypoint, Attrs, false) of
@ -364,7 +371,8 @@ expr_p(_, {Type, _, Bin})
Type == oracle_query_id -> Type == oracle_query_id ->
text(binary_to_list(aeser_api_encoder:encode(Type, Bin))); text(binary_to_list(aeser_api_encoder:encode(Type, Bin)));
expr_p(_, {string, _, <<>>}) -> text("\"\""); 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}) -> expr_p(_, {char, _, C}) ->
case C of case C of
$' -> text("'\\''"); $' -> text("'\\''");
@ -486,6 +494,3 @@ get_elifs(If = {'if', Ann, Cond, Then, Else}, Elifs) ->
end; end;
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}. 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]).

View File

@ -2,23 +2,22 @@
@compiler > 0 @compiler > 0
@compiler =< 10.1.1.1.1.1.2.3.4 @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- /** Multi-
* line * line
* comment * comment
*/ */
function foo : _ stateful function foo : _
entrypoint bar : int => (int * 'a) 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 = contract AllSyntax =
@ -47,6 +46,7 @@ contract AllSyntax =
goethe = () } goethe = () }
function f() = function f() =
let kp = "nietzsche"
let p = "Пушкин" let p = "Пушкин"
let k(x : bytes(8)) : bytes(8) = Bytes.to_int(#fedcba9876543210) let k(x : bytes(8)) : bytes(8) = Bytes.to_int(#fedcba9876543210)
@ -68,6 +68,7 @@ contract AllSyntax =
_ => 13 _ => 13
1::[2] => 2138 1::[2] => 2138
put(state{johann = 1}) put(state{johann = 1})
let m = {["foo"] = 19, /*hey wanna talk about inlined comments?*/ ["bar"] = 42} let m = {["foo"] = 19, /*hey wanna talk about inlined comments?*/ ["bar"] = 42}
let n = {} let n = {}
m{ ["x" = 0] @ z = z + state.johann } m{ ["x" = 0] @ z = z + state.johann }
@ -75,4 +76,3 @@ contract AllSyntax =
let sh : shakespeare(shakespeare(int)) = let sh : shakespeare(shakespeare(int)) =
{wolfgang = state} {wolfgang = state}
sh{wolfgang.wolfgang = sh.wolfgang} // comment sh{wolfgang.wolfgang = sh.wolfgang} // comment
/*