From 01051408788254641432f9958683d1a691eccf16 Mon Sep 17 00:00:00 2001 From: radrow Date: Mon, 17 May 2021 09:42:53 +0200 Subject: [PATCH] Fix failing tests --- src/aeso_ast_to_fcode.erl | 6 ++++-- src/aeso_code_errors.erl | 2 +- src/aeso_fcode_to_fate.erl | 15 +++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 3a965a9..835d4d0 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -719,14 +719,16 @@ expr_to_fcode(Env, Type, {app, _, Fun = {typed, _, FunE, {fun_t, _, NamedArgsT, case ArgsT of var_args -> fcode_error({var_args_not_set, FunE}); _ -> - FInitArgsT = aeb_fate_data:make_typerep({tuple, [type_to_fcode(Env, T) || T <- ArgsT]}), + %% Here we little cheat on the typechecker, but this inconsistency + %% is to be solved in `aeso_fcode_to_fate:type_to_scode/1` + FInitArgsT = aeb_fate_data:make_typerep([type_to_fcode(Env, T) || T <- ArgsT]), builtin_to_fcode(state_layout(Env), chain_clone, [{lit, FInitArgsT}|FArgs]) end; {builtin_u, chain_create, _Ar} -> case {ArgsT, Type} of {var_args, _} -> fcode_error({var_args_not_set, FunE}); {_, {con, _, Contract}} -> - FInitArgsT = aeb_fate_data:make_typerep({tuple, [type_to_fcode(Env, T) || T <- ArgsT]}), + FInitArgsT = aeb_fate_data:make_typerep([type_to_fcode(Env, T) || T <- ArgsT]), builtin_to_fcode(state_layout(Env), chain_create, [{lit, {contract_code, Contract}}, {lit, FInitArgsT}|FArgs]); {_, _} -> fcode_error({not_a_contract_type, Type}) end; diff --git a/src/aeso_code_errors.erl b/src/aeso_code_errors.erl index cc547b7..b3d1308 100644 --- a/src/aeso_code_errors.erl +++ b/src/aeso_code_errors.erl @@ -10,7 +10,7 @@ -export([format/1, pos/1]). -format({last_declaration_must_be_contract, Decl = {Kind, _, {con, _, C}, _}}) -> +format({last_declaration_must_be_main_contract, Decl = {Kind, _, {con, _, C}, _}}) -> Msg = io_lib:format("Expected a main contract as the last declaration instead of the ~p '~s'\n", [Kind, C]), mk_err(pos(Decl), Msg); diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 2186018..e93da66 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -125,6 +125,7 @@ type_to_scode(bits) -> bits; type_to_scode(any) -> any; type_to_scode({variant, Cons}) -> {variant, [{tuple, types_to_scode(Con)} || Con <- Cons]}; type_to_scode({list, Type}) -> {list, type_to_scode(Type)}; +type_to_scode({tuple, [Type]}) -> type_to_scode(Type); type_to_scode({tuple, Types}) -> {tuple, types_to_scode(Types)}; type_to_scode({map, Key, Val}) -> {map, type_to_scode(Key), type_to_scode(Val)}; type_to_scode({function, _Args, _Res}) -> {tuple, [string, any]}; @@ -135,7 +136,9 @@ type_to_scode({tvar, X}) -> put(?tvars, {I + 1, Vars#{ X => I }}), {tvar, I}; J -> {tvar, J} - end. + end; +type_to_scode(L) when is_list(L) -> {tuple, types_to_scode(L)}. + types_to_scode(Ts) -> lists:map(fun type_to_scode/1, Ts). @@ -580,22 +583,22 @@ builtin_to_scode(_Env, auth_tx, []) -> builtin_to_scode(Env, chain_bytecode_hash, [_Addr] = Args) -> call_to_scode(Env, aeb_fate_ops:bytecode_hash(?a, ?a), Args); builtin_to_scode(Env, chain_clone, - [TypeRep, GasCap, Value, Prot, Contract | InitArgs]) -> + [InitArgsT, GasCap, Value, Prot, Contract | InitArgs]) -> case GasCap of {builtin, call_gas_left, _} -> call_to_scode(Env, aeb_fate_ops:clone(?a, ?a, ?a, ?a), - [Contract, TypeRep, Value, Prot | InitArgs] + [Contract, InitArgsT, Value, Prot | InitArgs] ); _ -> call_to_scode(Env, aeb_fate_ops:clone_g(?a, ?a, ?a, ?a, ?a), - [Contract, TypeRep, Value, GasCap, Prot | InitArgs] + [Contract, InitArgsT, Value, GasCap, Prot | InitArgs] ) end; builtin_to_scode(Env, chain_create, - [ Code, TypeRep, Value | InitArgs]) -> + [ Code, InitArgsT, Value | InitArgs]) -> call_to_scode(Env, aeb_fate_ops:create(?a, ?a, ?a), - [Code, TypeRep, Value | InitArgs] + [Code, InitArgsT, Value | InitArgs] ). %% -- Operators --