Merge branch '99-ligo-dies-instead' into 'dev'

Resolve "ligo dies instead a when using the wrong type with map"

Closes #99

See merge request ligolang/ligo!283
This commit is contained in:
Rémi Lesenechal 2019-12-24 12:31:49 +00:00
commit e9c36f1688
7 changed files with 25 additions and 12 deletions

View File

@ -924,3 +924,7 @@ let%expect_test _ =
NIL operation ;
PAIR ;
DIP { DROP 2 } } } |}]
let%expect_test _ =
run_ligo_bad [ "compile-contract" ; contract "bad_type_operator.ligo" ; "main" ] ;
[%expect {| ligo: bad type operator (TO_Map (unit,unit)): |}] ;

View File

@ -190,7 +190,7 @@ let rec simpl_type_expression : Raw.type_expr -> type_expression result = fun te
let%bind cst =
trace (unknown_predefined_type name) @@
type_operators name.value in
ok @@ t_operator cst lst'
t_operator cst lst'
)
| TProd p -> (
let%bind tpl = simpl_list_type_expression @@ npseq_to_list p.value in

View File

@ -250,7 +250,7 @@ let rec simpl_type_expression (t:Raw.type_expr) : type_expression result =
let%bind cst =
trace (unknown_predefined_type name) @@
type_operators name.value in
ok @@ t_operator cst lst
t_operator cst lst
| TProd p ->
let%bind tpl = simpl_list_type_expression
@@ npseq_to_list p.value in

View File

@ -8,8 +8,8 @@ val list_sep_d : (formatter -> 'a -> unit) -> formatter -> 'a list -> unit
val smap_sep_d : (formatter -> 'a -> unit) -> formatter -> 'a Map.String.t -> unit
val type_expression : formatter -> type_expression -> unit
*)
val type_expression : formatter -> type_expression -> unit
val literal : formatter -> literal -> unit

View File

@ -12,6 +12,10 @@ module Errors = struct
("location" , fun () -> Format.asprintf "%a" Location.pp location) ;
] in
error ~data title message
let bad_type_operator type_op =
let title () = Format.asprintf "bad type operator %a" (Stage_common.PP.type_operator PP.type_expression) type_op in
let message () = "" in
error title message
end
open Errors
@ -57,14 +61,15 @@ let t_set key : type_expression = make_t @@ T_operator (TC_set key
let t_contract contract : type_expression = make_t @@ T_operator (TC_contract contract)
(* TODO find a better way than using list*)
let t_operator op lst: type_expression =
match op with
| TC_set _ -> t_set (List.hd lst)
| TC_list _ -> t_list (List.hd lst)
| TC_option _ -> t_option (List.hd lst)
| TC_map (_,_) -> let tl = List.tl lst in t_map (List.hd lst) (List.hd tl)
| TC_big_map (_,_) -> let tl = List.tl lst in t_big_map (List.hd lst) (List.hd tl)
| TC_contract _ -> t_contract (List.hd lst)
let t_operator op lst: type_expression result =
match op,lst with
| TC_set _ , [t] -> ok @@ t_set t
| TC_list _ , [t] -> ok @@ t_list t
| TC_option _ , [t] -> ok @@ t_option t
| TC_map (_,_) , [kt;vt] -> ok @@ t_map kt vt
| TC_big_map (_,_) , [kt;vt] -> ok @@ t_big_map kt vt
| TC_contract _ , [t] -> ok @@ t_contract t
| _ , _ -> fail @@ bad_type_operator op
let location_wrap ?(loc = Location.generated) expression =
let location = loc in

View File

@ -42,7 +42,7 @@ val ez_t_sum : ( string * type_expression ) list -> type_expression
val t_function : type_expression -> type_expression -> type_expression
val t_map : type_expression -> type_expression -> type_expression
val t_operator : 'a type_operator -> type_expression list -> type_expression
val t_operator : type_expression type_operator -> type_expression list -> type_expression result
val t_set : type_expression -> type_expression
val e_var : ?loc:Location.t -> string -> expression

View File

@ -0,0 +1,4 @@
type t is (nat * nat)
type s is map(t)
function main (const u : unit; const s : s) : (list(operation) * s) is ((nil : list(operation)), s)