From 427a8886a1164c8d6fd07dea2444f4671910695d Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 4 May 2022 19:10:50 +0400 Subject: [PATCH] Show the file name in the location if the file is included --- src/aeso_ast_infer_types.erl | 10 +++++++--- test/aeso_compiler_tests.erl | 8 +++++++- ...namespace_clash.aes => namespace_clash_builtin.aes} | 0 test/contracts/namespace_clash_included.aes | 9 +++++++++ test/contracts/namespace_clash_same_file.aes | 8 ++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) rename test/contracts/{namespace_clash.aes => namespace_clash_builtin.aes} (100%) create mode 100644 test/contracts/namespace_clash_included.aes create mode 100644 test/contracts/namespace_clash_same_file.aes diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 4ef4403..ead0fe6 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -3490,6 +3490,7 @@ pp_type(Label, Type) -> prettypr:format(prettypr:beside(prettypr:text(Label), aeso_pretty:type(Type, [show_generated])), 80, 80). src_file(T) -> aeso_syntax:get_ann(file, T, no_file). +include_type(T) -> aeso_syntax:get_ann(include_type, T, none). line_number(T) -> aeso_syntax:get_ann(line, T, 0). column_number(T) -> aeso_syntax:get_ann(col, T, 0). @@ -3497,13 +3498,16 @@ pos(T) -> aeso_errors:pos(src_file(T), line_number(T), column_number(T)). pos(L, C) -> aeso_errors:pos(L, C). loc(T) -> - {line_number(T), column_number(T)}. + {src_file(T), include_type(T), line_number(T), column_number(T)}. pp_loc(T) -> - {Line, Col} = loc(T), + {File, IncludeType, Line, Col} = loc(T), case {Line, Col} of {0, 0} -> "(builtin location)"; - _ -> io_lib:format("line ~p, column ~p", [Line, Col]) + _ -> case IncludeType of + none -> io_lib:format("line ~p, column ~p", [Line, Col]); + _ -> io_lib:format("line ~p, column ~p in ~s", [Line, Col, File]) + end end. plural(No, _Yes, [_]) -> No; diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index fa3cb6a..ae4f834 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -425,9 +425,15 @@ failing_contracts() -> "The field `y` is missing when constructing an element of type `r(int)`">>, <>]) - , ?TYPE_ERROR(namespace_clash, + , ?TYPE_ERROR(namespace_clash_builtin, [<>]) + , ?TYPE_ERROR(namespace_clash_included, + [<>]) + , ?TYPE_ERROR(namespace_clash_same_file, + [<>]) , ?TYPE_ERROR(bad_events, [<>, diff --git a/test/contracts/namespace_clash.aes b/test/contracts/namespace_clash_builtin.aes similarity index 100% rename from test/contracts/namespace_clash.aes rename to test/contracts/namespace_clash_builtin.aes diff --git a/test/contracts/namespace_clash_included.aes b/test/contracts/namespace_clash_included.aes new file mode 100644 index 0000000..bf2931d --- /dev/null +++ b/test/contracts/namespace_clash_included.aes @@ -0,0 +1,9 @@ +@compiler >= 6 + +include "BLS12_381.aes" + +namespace BLS12_381 = + type fp = int + +main contract Bug = + type number = int diff --git a/test/contracts/namespace_clash_same_file.aes b/test/contracts/namespace_clash_same_file.aes new file mode 100644 index 0000000..c969b18 --- /dev/null +++ b/test/contracts/namespace_clash_same_file.aes @@ -0,0 +1,8 @@ +namespace Nmsp = + type x = int + +namespace Nmsp = + type y = string + +main contract Bug = + type number = int