From 7c6756158512e85ce5f82d1184be58e0479f3b8b Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Fri, 19 May 2023 18:46:04 +0300 Subject: [PATCH] Fix issues with pretty-printing of fexprs --- src/aeso_ast_to_fcode.erl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 8061644..997ba02 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -2301,6 +2301,8 @@ pp_par(Xs) -> prettypr:par(Xs). -spec pp_fexpr(fexpr()) -> prettypr:document(). pp_fexpr({lit, _, {typerep, T}}) -> pp_ftype(T); +pp_fexpr({lit, _, {contract_code, Contract}}) -> + pp_beside(pp_text("contract "), pp_text(Contract)); pp_fexpr({lit, _, {Tag, Lit}}) -> aeso_pretty:expr({Tag, [], Lit}); pp_fexpr({nil, _}) -> @@ -2371,9 +2373,7 @@ pp_fexpr({set_state, FAnn, R, A}) -> pp_call(pp_text("set_state"), [{lit, FAnn, {int, R}}, A]); pp_fexpr({get_state, FAnn, R}) -> pp_call(pp_text("get_state"), [{lit, FAnn, {int, R}}]); -pp_fexpr({switch, _, Split}) -> pp_split(Split); -pp_fexpr({contract_code, Contract}) -> - pp_beside(pp_text("contract "), pp_text(Contract)). +pp_fexpr({switch, _, Split}) -> pp_split(Split). -spec pp_call(prettypr:document(), [fexpr()]) -> prettypr:document(). pp_call(Fun, Args) -> @@ -2403,7 +2403,11 @@ pp_ftype({variant, Cons}) -> [ case Args of [] -> pp_fexpr({con, [], [], I - 1, []}); _ -> pp_beside(pp_fexpr({con, [], [], I - 1, []}), pp_ftype({tuple, Args})) - end || {I, Args} <- indexed(Cons)])). + end || {I, Args} <- indexed(Cons)])); +pp_ftype([]) -> + %% NOTE: This could happen with `{typerep, []}` since `[]` is not a ftype(). + %% TODO: It would be better to make sure that `{typerep, []}` does not arrive here. + pp_text("[]"). -spec pp_split(fsplit()) -> prettypr:document(). pp_split({nosplit, _, E}) -> pp_fexpr(E);