diff --git a/gitlab-pages/docs/advanced/entrypoints-contracts.md b/gitlab-pages/docs/advanced/entrypoints-contracts.md index 499d07c58..c2232e494 100644 --- a/gitlab-pages/docs/advanced/entrypoints-contracts.md +++ b/gitlab-pages/docs/advanced/entrypoints-contracts.md @@ -310,7 +310,7 @@ let main (action, store: parameter * storage) : return = ```reasonligo group=c let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); -let main = ((action, store) : (parameter, storage)) : storage => { +let main = ((action, store) : (parameter, storage)) : return => { if (Tezos.source != owner) { (failwith ("Access denied.") : return); } else { (([] : list (operation)), store); }; }; @@ -478,4 +478,3 @@ let proxy = ((action, store): (parameter, storage)) : return => { > *deprecated*. - diff --git a/src/passes/1-parser/reasonligo/Parser.mly b/src/passes/1-parser/reasonligo/Parser.mly index defde2e55..d24e3f832 100644 --- a/src/passes/1-parser/reasonligo/Parser.mly +++ b/src/passes/1-parser/reasonligo/Parser.mly @@ -558,9 +558,13 @@ fun_expr: in raise (Error (WrongFunctionArguments e)) in let binders = fun_args_to_pattern $1 in + let lhs_type = match $1 with + EAnnot {value = {inside = _ , _, t; _}; region = r} -> Some (r,t) + | _ -> None + in let f = {kwd_fun; binders; - lhs_type=None; + lhs_type; arrow; body } diff --git a/src/passes/2-simplify/cameligo.ml b/src/passes/2-simplify/cameligo.ml index 910da246f..569df20b3 100644 --- a/src/passes/2-simplify/cameligo.ml +++ b/src/passes/2-simplify/cameligo.ml @@ -828,6 +828,18 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result ok (Raw.EFun {region=Region.ghost ; value=fun_},List.fold_right' aux lhs_type' ty) in let%bind rhs' = simpl_expression let_rhs in + let%bind lhs_type = match lhs_type with + | None -> (match let_rhs with + | EFun {value={binders;lhs_type}} -> + let f_args = nseq_to_list (binders) in + let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in + let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in + let aux acc ty = Option.map (t_function (snd ty)) acc in + ok @@ (List.fold_right' aux lhs_type' ty) + | _ -> ok None + ) + | Some t -> ok @@ Some t + in ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type , inline, rhs'))] ) diff --git a/src/test/contracts/balance_constant.religo b/src/test/contracts/balance_constant.religo index 1d136052b..33c1fd725 100644 --- a/src/test/contracts/balance_constant.religo +++ b/src/test/contracts/balance_constant.religo @@ -12,7 +12,7 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"} type storage = tez; -let main2 = (p : unit, storage) => +let main2 = (p : unit, s: storage) => ([]: list (operation), Tezos.balance); let main = (x : (unit, storage)) => main2 (x[0], x[1]); diff --git a/src/test/contracts/set_arithmetic.religo b/src/test/contracts/set_arithmetic.religo index a219fba9b..ed8f7a075 100644 --- a/src/test/contracts/set_arithmetic.religo +++ b/src/test/contracts/set_arithmetic.religo @@ -6,10 +6,10 @@ let literal_op = (p: unit) : set (string) => let add_op = (s: set (string)) : set (string) => Set.add ("foobar", s); -let remove_op = (s: set (string)) : set(string) => +let remove_op = (s: set (string)) : set (string) => Set.remove ("foobar", s); -let remove_deep = (s: (set (string), nat)): (set (string), nat) => +let remove_deep = (s: (set (string), nat)): set (string) => Set.remove ("foobar", s[0]); let mem_op = (s: set (string)) : bool =>