List valid exprs in the error message for invalid exprs

This commit is contained in:
Gaith Hallak 2022-12-19 14:18:56 +03:00
parent d34760b990
commit ad851854be
2 changed files with 23 additions and 11 deletions

View File

@ -3937,7 +3937,9 @@ mk_error({invalid_const_id, Ann}) ->
mk_t_err(pos(Ann), Msg); mk_t_err(pos(Ann), Msg);
mk_error({invalid_const_expr, ConstId}) -> mk_error({invalid_const_expr, ConstId}) ->
Msg = io_lib:format("Invalid expression in the definition of the constant `~s`", [name(ConstId)]), Msg = io_lib:format("Invalid expression in the definition of the constant `~s`", [name(ConstId)]),
mk_t_err(pos(aeso_syntax:get_ann(ConstId)), Msg); Cxt = "You can only use the following expressions as constants: "
"literals, lists, tuples, maps, and other constants",
mk_t_err(pos(aeso_syntax:get_ann(ConstId)), Msg, Cxt);
mk_error({illegal_const_in_interface, Ann}) -> mk_error({illegal_const_in_interface, Ann}) ->
Msg = "Cannot define toplevel constants inside a contract interface", Msg = "Cannot define toplevel constants inside a contract interface",
mk_t_err(pos(Ann), Msg); mk_t_err(pos(Ann), Msg);

View File

@ -1230,25 +1230,35 @@ failing_contracts() ->
]) ])
, ?TYPE_ERROR(toplevel_constants_invalid_expr, , ?TYPE_ERROR(toplevel_constants_invalid_expr,
[<<?Pos(10,9) [<<?Pos(10,9)
"Invalid expression in the definition of the constant `c01`">>, "Invalid expression in the definition of the constant `c01`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(11,9) <<?Pos(11,9)
"Invalid expression in the definition of the constant `c02`">>, "Invalid expression in the definition of the constant `c02`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(12,9) <<?Pos(12,9)
"Invalid expression in the definition of the constant `c03`">>, "Invalid expression in the definition of the constant `c03`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(13,9) <<?Pos(13,9)
"Invalid expression in the definition of the constant `c04`">>, "Invalid expression in the definition of the constant `c04`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(14,9) <<?Pos(14,9)
"Invalid expression in the definition of the constant `c05`">>, "Invalid expression in the definition of the constant `c05`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(17,9) <<?Pos(17,9)
"Invalid expression in the definition of the constant `c07`">>, "Invalid expression in the definition of the constant `c07`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(18,9) <<?Pos(18,9)
"Invalid expression in the definition of the constant `c08`">>, "Invalid expression in the definition of the constant `c08`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(19,9) <<?Pos(19,9)
"Invalid expression in the definition of the constant `c09`">>, "Invalid expression in the definition of the constant `c09`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(20,9) <<?Pos(20,9)
"Invalid expression in the definition of the constant `c10`">>, "Invalid expression in the definition of the constant `c10`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>,
<<?Pos(21,9) <<?Pos(21,9)
"Invalid expression in the definition of the constant `c11`">> "Invalid expression in the definition of the constant `c11`\n"
"You can only use the following expressions as constants: literals, lists, tuples, maps, and other constants">>
]) ])
, ?TYPE_ERROR(toplevel_constants_invalid_id, , ?TYPE_ERROR(toplevel_constants_invalid_id,
[<<?Pos(2,9) [<<?Pos(2,9)