diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 97ad461..8c33012 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -2440,7 +2440,7 @@ pp_expr(Label, Expr) -> pp_type(Label, Type) -> prettypr:format(prettypr:beside(prettypr:text(Label), aeso_pretty:type(Type, [show_generated]))). -src_file(T) -> aeso_syntax:get_ann(src_file, T, no_file). +src_file(T) -> aeso_syntax:get_ann(file, T, no_file). line_number(T) -> aeso_syntax:get_ann(line, T, 0). column_number(T) -> aeso_syntax:get_ann(col, T, 0). diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index 7a8dd7d..255757c 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -152,11 +152,17 @@ not_yet_compilable(aevm) -> []. %% Contracts that should produce type errors --define(Pos(Line, Col), "At line " ??Line ", col " ??Col ":\n"). --define(Pos(File, Line, Col), "In '" File ".aes' at line " ??Line ", col " ??Col ":\n"). +-define(Pos(File, Line, Col), "In '", (list_to_binary(File))/binary, ".aes' at line " ??Line ", col " ??Col ":\n"). +-define(Pos(Line, Col), ?Pos(__File, Line, Col)). + +-define(TEST(Name, Errs), + (fun() -> + __File = ??Name, + {__File, Errs} + end)()). failing_contracts() -> - [ {"name_clash", + [ ?TEST(name_clash, [< <>]} - , {"type_errors", + " - line 17, column 3">>]) + , ?TEST(type_errors, [<>, < <>, <>]} - , {"init_type_error", + "Let binding at line 58, column 5 must be followed by an expression">>]) + , ?TEST(init_type_error, [<>]} - , {"missing_state_type", + "when checking that 'init' returns a value of type 'state' at line 7, column 3">>]) + , ?TEST(missing_state_type, [<>]} - , {"missing_fields_in_record_expression", + "when checking that 'init' returns a value of type 'state' at line 5, column 3">>]) + , ?TEST(missing_fields_in_record_expression, [<>, <>, <>]} - , {"namespace_clash", + "The fields y, z are missing when constructing an element of type r('a) (at line 6, column 42)">>]) + , ?TEST(namespace_clash, [<>]} - , {"bad_events", + "The contract Call (at line 4, column 10) has the same name as a namespace at (builtin location)">>]) + , ?TEST(bad_events, [<>, <>]} - , {"bad_events2", + "The indexed type alias_string (at line 10, column 25) equals string which is not a word type">>]) + , ?TEST(bad_events2, [<>, <>]} - , {"type_clash", + "The event constructor BadEvent2 (at line 10, column 7) has too many indexed values (max 3)">>]) + , ?TEST(type_clash, [< Remote.themap\n" "against the expected type\n" - " (gas : int, value : int) => map(string, int)">>]} - , {"bad_include_and_ns", + " (gas : int, value : int) => map(string, int)">>]) + , ?TEST(bad_include_and_ns, [<>, <>]} - , {"bad_address_literals", + "Nested namespace not allowed\nNamespace 'Foo' at line 3, column 13 not defined at top level.">>]) + , ?TEST(bad_address_literals, [< "when checking the type of the expression at line 7, column 5\n" " ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt : address\n" "against the expected type\n" - " bytes(32)">>]} - , {"stateful", + " bytes(32)">>]) + , ?TEST(stateful, [<>, < <>, <>]} - , {"bad_init_state_access", + "Cannot pass non-zero value argument 1000 (at line 52, column 17)\nin the definition of non-stateful function fail8.">>]) + , ?TEST(bad_init_state_access, [< <>]} - , {"field_parse_error", + " - state (at line 13, column 13)">>]) + , ?TEST(field_parse_error, [<>]} - , {"modifier_checks", + "Cannot use nested fields or keys in record construction: p.x">>]) + , ?TEST(modifier_checks, [<>, < <>, < unit">>]} - , {"list_comp_not_a_list", + "Use 'entrypoint' instead of 'function' for public function foo (at line 6, column 3):\n entrypoint foo : () => unit">>]) + , ?TEST(list_comp_not_a_list, [<> - ]} - , {"list_comp_if_not_bool", + ]) + , ?TEST(list_comp_if_not_bool, [<> - ]} - , {"list_comp_bad_shadow", + ]) + , ?TEST(list_comp_bad_shadow, [<> - ]} - , {"map_as_map_key", + ]) + , ?TEST(map_as_map_key, [< <>]} - , {"calling_init_function", + "Map keys cannot contain other maps.">>]) + , ?TEST(calling_init_function, [<>]} + "and cannot be called from the contract code.">>]) ]. -define(Path(File), "code_errors/" ??File).