From 1e5abda3eed2c66f005457293c9924a4600ddd32 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 2 Mar 2020 12:53:03 +0100 Subject: [PATCH] create contract : conservative restrictions & errors in typer, before inlining/beta optimizations --- src/passes/4-typer-old/typer.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/passes/4-typer-old/typer.ml b/src/passes/4-typer-old/typer.ml index e966b5a52..1b220754f 100644 --- a/src/passes/4-typer-old/typer.ml +++ b/src/passes/4-typer-old/typer.ml @@ -154,9 +154,18 @@ module Errors = struct ] in error ~data title message () - let fvs_in_create_contract_lambda (e : I.expression) (case : Ast_typed.expression_variable) () = + let fvs_in_create_contract_lambda (e : I.expression) (fvar : Ast_typed.expression_variable) () = let title = (thunk "No free variable allowed in this lambda") in - let message () = Format.asprintf "%a " Var.pp case in + let message () = Format.asprintf "variable '%a'" Var.pp fvar in + let data = [ + ("expression" , fun () -> Format.asprintf "%a" I.PP.expression e) ; + ("location" , fun () -> Format.asprintf "%a" Location.pp e.location) + ] in + error ~data title message () + + let create_contract_lambda (cst : I.constant') (e : I.expression) () = + let title () = Format.asprintf "%a first argument must be inlined" I.PP.constant cst in + let message () = Format.asprintf "contract code can be inlined using a lambda" in let data = [ ("expression" , fun () -> Format.asprintf "%a" I.PP.expression e) ; ("location" , fun () -> Format.asprintf "%a" Location.pp e.location) @@ -713,7 +722,7 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let fvs = Free_variables.lambda [] l in if List.length fvs = 0 then ok () else fail @@ fvs_in_create_contract_lambda ae (List.hd fvs) - | _ -> ok () + | _ -> fail @@ create_contract_lambda C_CREATE_CONTRACT ae in let tv_lst = List.map get_type_expression lst' in let%bind (name', tv) =