Fix list comprehension bug #699
@ -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),
|
||||
|
@ -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 '[ ]'
|
||||
|
@ -138,6 +138,7 @@ compilable_contracts() ->
|
||||
"test",
|
||||
"builtin_bug",
|
||||
"builtin_map_get_bug",
|
||||
"lc_record_bug",
|
||||
"nodeadcode",
|
||||
"deadcode",
|
||||
"variant_types",
|
||||
|
4
test/contracts/lc_record_bug.aes
Normal file
4
test/contracts/lc_record_bug.aes
Normal file
@ -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 ]
|
Loading…
x
Reference in New Issue
Block a user