Add include directive
Add an include directive to include namespaces into a contract. Only allowed at the top level. To allow includes, either call through aeso_compiler:file or set the option `allow_include` (and add `include_path`(s)).
This commit is contained in:
committed by
Ulf Norell
parent
0a5b80668f
commit
2b7490776e
@@ -23,8 +23,12 @@ simple_compile_test_() ->
|
||||
end} || ContractName <- compilable_contracts() ] ++
|
||||
[ {"Testing error messages of " ++ ContractName,
|
||||
fun() ->
|
||||
<<"Type errors\n",ErrorString/binary>> = compile(ContractName),
|
||||
check_errors(lists:sort(ExpectedErrors), ErrorString)
|
||||
case compile(ContractName, false) of
|
||||
<<"Type errors\n", ErrorString/binary>> ->
|
||||
check_errors(lists:sort(ExpectedErrors), ErrorString);
|
||||
<<"Parse errors\n", ErrorString/binary>> ->
|
||||
check_errors(lists:sort(ExpectedErrors), ErrorString)
|
||||
end
|
||||
end} ||
|
||||
{ContractName, ExpectedErrors} <- failing_contracts() ] ++
|
||||
[ {"Testing deadcode elimination",
|
||||
@@ -46,9 +50,13 @@ check_errors(Expect, ErrorString) ->
|
||||
{Missing, Extra} -> ?assertEqual(Missing, Extra)
|
||||
end.
|
||||
|
||||
compile(Name) ->
|
||||
compile(Name) -> compile(Name, true).
|
||||
|
||||
compile(Name, AllowInc) ->
|
||||
String = aeso_test_utils:read_contract(Name),
|
||||
case aeso_compiler:from_string(String, []) of
|
||||
case aeso_compiler:from_string(String, [{include_path, [aeso_test_utils:contract_path()]},
|
||||
{allow_include, AllowInc},
|
||||
{src_file, Name}]) of
|
||||
{ok,Map} -> Map;
|
||||
{error,ErrorString} -> ErrorString
|
||||
end.
|
||||
@@ -78,7 +86,8 @@ compilable_contracts() ->
|
||||
"deadcode",
|
||||
"variant_types",
|
||||
"state_handling",
|
||||
"events"
|
||||
"events",
|
||||
"include"
|
||||
].
|
||||
|
||||
%% Contracts that should produce type errors
|
||||
@@ -192,4 +201,6 @@ failing_contracts() ->
|
||||
" r.foo : (gas : int, value : int) => Remote.themap\n"
|
||||
"against the expected type\n"
|
||||
" (gas : int, value : int) => map(string, int)">>]}
|
||||
, {"include",
|
||||
[<<"file include, line 1, column 9: includes not allowed in this context\n">>]}
|
||||
].
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
include "included.aes"
|
||||
include "../contracts/included2.aes"
|
||||
|
||||
contract Include =
|
||||
// include "maps.aes"
|
||||
function foo() =
|
||||
Included.foo() < Included2a.bar()
|
||||
|
||||
function bar() =
|
||||
Included2b.foo() > Included.foo()
|
||||
@@ -0,0 +1,2 @@
|
||||
namespace Included =
|
||||
function foo() = 42
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Included2a =
|
||||
function bar() = 43
|
||||
|
||||
namespace Included2b =
|
||||
function foo() = 44
|
||||
Reference in New Issue
Block a user