From ad851854bed14f36d2393b457eb2f893a7c203e0 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Mon, 19 Dec 2022 14:18:56 +0300 Subject: [PATCH] List valid exprs in the error message for invalid exprs --- src/aeso_ast_infer_types.erl | 4 +++- test/aeso_compiler_tests.erl | 30 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index ce19668..b4b135d 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -3937,7 +3937,9 @@ mk_error({invalid_const_id, Ann}) -> mk_t_err(pos(Ann), Msg); mk_error({invalid_const_expr, 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}) -> Msg = "Cannot define toplevel constants inside a contract interface", mk_t_err(pos(Ann), Msg); diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index d2953cd..1bd84a0 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -1230,25 +1230,35 @@ failing_contracts() -> ]) , ?TYPE_ERROR(toplevel_constants_invalid_expr, [<>, + "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">>, <>, + "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">>, <>, + "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">>, <>, + "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">>, <>, + "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">>, <>, + "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">>, <>, + "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">>, <>, + "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">>, <>, + "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">>, <> + "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, [<