Add error messages for bad include and nested namespace
This commit is contained in:
parent
2b7490776e
commit
421bc01012
@ -566,11 +566,13 @@ infer_constant({letval, Attrs,_Pattern, Type, E}) ->
|
|||||||
infer_contract(Env, What, Defs) ->
|
infer_contract(Env, What, Defs) ->
|
||||||
Kind = fun({type_def, _, _, _, _}) -> type;
|
Kind = fun({type_def, _, _, _, _}) -> type;
|
||||||
({letfun, _, _, _, _, _}) -> function;
|
({letfun, _, _, _, _, _}) -> function;
|
||||||
({fun_decl, _, _, _}) -> prototype
|
({fun_decl, _, _, _}) -> prototype;
|
||||||
|
(_) -> unexpected
|
||||||
end,
|
end,
|
||||||
Get = fun(K) -> [ Def || Def <- Defs, Kind(Def) == K ] end,
|
Get = fun(K) -> [ Def || Def <- Defs, Kind(Def) == K ] end,
|
||||||
{Env1, TypeDefs} = check_typedefs(Env, Get(type)),
|
{Env1, TypeDefs} = check_typedefs(Env, Get(type)),
|
||||||
create_type_errors(),
|
create_type_errors(),
|
||||||
|
check_unexpected(Get(unexpected)),
|
||||||
Env2 =
|
Env2 =
|
||||||
case What of
|
case What of
|
||||||
namespace -> Env1;
|
namespace -> Env1;
|
||||||
@ -646,6 +648,9 @@ check_typedef(Env, {variant_t, Cons}) ->
|
|||||||
{variant_t, [ {constr_t, Ann, Con, [ check_type(Env, Arg) || Arg <- Args ]}
|
{variant_t, [ {constr_t, Ann, Con, [ check_type(Env, Arg) || Arg <- Args ]}
|
||||||
|| {constr_t, Ann, Con, Args} <- Cons ]}.
|
|| {constr_t, Ann, Con, Args} <- Cons ]}.
|
||||||
|
|
||||||
|
check_unexpected(Xs) ->
|
||||||
|
[ type_error(X) || X <- Xs ].
|
||||||
|
|
||||||
-spec check_type(env(), aeso_syntax:type()) -> aeso_syntax:type().
|
-spec check_type(env(), aeso_syntax:type()) -> aeso_syntax:type().
|
||||||
check_type(Env, T) ->
|
check_type(Env, T) ->
|
||||||
check_type(Env, T, 0).
|
check_type(Env, T, 0).
|
||||||
@ -1869,6 +1874,12 @@ pp_error({duplicate_definition, Name, Locs}) ->
|
|||||||
pp_error({duplicate_scope, Kind, Name, OtherKind, L}) ->
|
pp_error({duplicate_scope, Kind, Name, OtherKind, L}) ->
|
||||||
io_lib:format("The ~p ~s (at ~s) has the same name as a ~p at ~s\n",
|
io_lib:format("The ~p ~s (at ~s) has the same name as a ~p at ~s\n",
|
||||||
[Kind, pp(Name), pp_loc(Name), OtherKind, pp_loc(L)]);
|
[Kind, pp(Name), pp_loc(Name), OtherKind, pp_loc(L)]);
|
||||||
|
pp_error({include, {string, Pos, Name}}) ->
|
||||||
|
io_lib:format("Include of '~s' at ~s\nnot allowed, include only allowed at top level.\n",
|
||||||
|
[binary_to_list(Name), pp_loc(Pos)]);
|
||||||
|
pp_error({namespace, _Pos, {con, Pos, Name}, _Def}) ->
|
||||||
|
io_lib:format("Nested namespace not allowed\nNamespace '~s' at ~s not defined at top level.\n",
|
||||||
|
[Name, pp_loc(Pos)]);
|
||||||
pp_error(Err) ->
|
pp_error(Err) ->
|
||||||
io_lib:format("Unknown error: ~p\n", [Err]).
|
io_lib:format("Unknown error: ~p\n", [Err]).
|
||||||
|
|
||||||
|
@ -203,4 +203,7 @@ failing_contracts() ->
|
|||||||
" (gas : int, value : int) => map(string, int)">>]}
|
" (gas : int, value : int) => map(string, int)">>]}
|
||||||
, {"include",
|
, {"include",
|
||||||
[<<"file include, line 1, column 9: includes not allowed in this context\n">>]}
|
[<<"file include, line 1, column 9: includes not allowed in this context\n">>]}
|
||||||
|
, {"bad_include_and_ns",
|
||||||
|
[<<"Include of 'included.aes' at line 2, column 11\nnot allowed, include only allowed at top level.">>,
|
||||||
|
<<"Nested namespace not allowed\nNamespace 'Foo' at line 3, column 13 not defined at top level.">>]}
|
||||||
].
|
].
|
||||||
|
6
test/contracts/bad_include_and_ns.aes
Normal file
6
test/contracts/bad_include_and_ns.aes
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
contract Bad =
|
||||||
|
include "included.aes"
|
||||||
|
namespace Foo =
|
||||||
|
function foo() = 42
|
||||||
|
|
||||||
|
function foo() = 43
|
@ -2,7 +2,6 @@ include "included.aes"
|
|||||||
include "../contracts/included2.aes"
|
include "../contracts/included2.aes"
|
||||||
|
|
||||||
contract Include =
|
contract Include =
|
||||||
// include "maps.aes"
|
|
||||||
function foo() =
|
function foo() =
|
||||||
Included.foo() < Included2a.bar()
|
Included.foo() < Included2a.bar()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user