diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 565c34d..d2705e0 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -1138,7 +1138,7 @@ infer_expr(Env, {list, As, Elems}) -> NewElems = [check_expr(Env, X, ElemType) || X <- Elems], {typed, As, {list, As, NewElems}, {app_t, As, {id, As, "list"}, [ElemType]}}; infer_expr(Env, {list_comp, As, Yield, []}) -> - {typed, _, TypedYield, Type} = infer_expr(Env, Yield), + {typed, _, _, Type} = TypedYield = infer_expr(Env, Yield), {typed, As, {list_comp, As, TypedYield, []}, {app_t, As, {id, As, "list"}, [Type]}}; infer_expr(Env, {list_comp, As, Yield, [{comprehension_bind, Arg, BExpr}|Rest]}) -> BindVarType = fresh_uvar(As), diff --git a/src/aeso_pretty.erl b/src/aeso_pretty.erl index 2472ead..6a362de 100644 --- a/src/aeso_pretty.erl +++ b/src/aeso_pretty.erl @@ -305,6 +305,8 @@ expr_p(_, {tuple, _, Es}) -> tuple(lists:map(fun expr/1, Es)); expr_p(_, {list, _, Es}) -> list(lists:map(fun expr/1, Es)); +expr_p(_, {list_comp, _, E, Binds}) -> + list([follow(expr(E), hsep(text("|"), par(punctuate(text(","), lists:map(fun lc_bind/1, Binds)), 0)), 0)]); expr_p(_, {record, _, Fs}) -> record(lists:map(fun field/1, Fs)); expr_p(_, {map, Ann, KVs}) -> @@ -387,6 +389,13 @@ stmt_p({else, Else}) -> _ -> block_expr(200, text("else"), Else) end. +lc_bind({comprehension_bind, P, E}) -> + follow(hsep(expr(P), text("<-")), expr(E)); +lc_bind({comprehension_if, _, E}) -> + beside([text("if("), expr(E), text(")")]); +lc_bind(Let) -> + letdecl("let", Let). + -spec bin_prec(aeso_syntax:bin_op()) -> {integer(), integer(), integer()}. bin_prec('..') -> { 0, 0, 0}; %% Always printed inside '[ ]' bin_prec('=') -> { 0, 0, 0}; %% Always printed inside '[ ]' diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index c5912cd..5021139 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -138,6 +138,7 @@ compilable_contracts() -> "test", "builtin_bug", "builtin_map_get_bug", + "lc_record_bug", "nodeadcode", "deadcode", "variant_types", diff --git a/test/contracts/lc_record_bug.aes b/test/contracts/lc_record_bug.aes new file mode 100644 index 0000000..dcce24d --- /dev/null +++ b/test/contracts/lc_record_bug.aes @@ -0,0 +1,4 @@ +contract Foo = + record r = {x : int} + // Crashed in the backend due to missing type annotation on the lc body. + entrypoint lc(xs) = [ {x = x} | x <- xs ]