Merge branch 'feature/unsupported_ass_None' into 'dev'

Feature/unsupported_ass_none

See merge request ligolang/ligo!118
This commit is contained in:
Christian Rinderknecht 2019-10-07 16:31:19 +00:00
commit 6f414a8ad2
8 changed files with 20 additions and 28 deletions

View File

@ -406,9 +406,7 @@ and lhs =
Path of path Path of path
| MapPath of map_lookup reg | MapPath of map_lookup reg
and rhs = and rhs = expr
Expr of expr
| NoneExpr of c_None
and loop = and loop =
While of while_loop reg While of while_loop reg
@ -758,9 +756,7 @@ let lhs_to_region : lhs -> Region.t = function
Path path -> path_to_region path Path path -> path_to_region path
| MapPath {region; _} -> region | MapPath {region; _} -> region
let rhs_to_region = function let rhs_to_region = expr_to_region
Expr e -> expr_to_region e
| NoneExpr r -> r
let selection_to_region = function let selection_to_region = function
FieldName {region; _} FieldName {region; _}

View File

@ -390,9 +390,7 @@ and lhs =
Path of path Path of path
| MapPath of map_lookup reg | MapPath of map_lookup reg
and rhs = and rhs = expr
Expr of expr
| NoneExpr of c_None
and loop = and loop =
While of while_loop reg While of while_loop reg

View File

@ -591,7 +591,7 @@ assignment:
in {region; value}} in {region; value}}
rhs: rhs:
expr { Expr $1 } expr { $1 }
lhs: lhs:
path { Path $1 } path { Path $1 }

View File

@ -309,9 +309,7 @@ and print_assignment {value; _} =
print_token assign ":="; print_token assign ":=";
print_rhs rhs print_rhs rhs
and print_rhs = function and print_rhs e = print_expr e
Expr e -> print_expr e
| NoneExpr r -> print_token r "None"
and print_lhs = function and print_lhs = function
Path path -> print_path path Path path -> print_path path

View File

@ -26,16 +26,6 @@ module Errors = struct
] in ] in
error ~data title message error ~data title message
let unsupported_ass_None region =
let title () = "assignment of None" in
let message () =
Format.asprintf "assignments of None are not supported yet" in
let data = [
("none_expr",
fun () -> Format.asprintf "%a" Location.pp_lift @@ region)
] in
error ~data title message
let bad_bytes loc str = let bad_bytes loc str =
let title () = "bad bytes string" in let title () = "bad bytes string" in
let message () = let message () =
@ -793,10 +783,7 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu
) )
| Assign a -> ( | Assign a -> (
let (a , loc) = r_split a in let (a , loc) = r_split a in
let%bind value_expr = match a.rhs with let%bind value_expr = simpl_expression a.rhs in
| Expr e -> simpl_expression e
| NoneExpr reg -> fail @@ unsupported_ass_None reg
in
match a.lhs with match a.lhs with
| Path path -> ( | Path path -> (
let (name , path') = simpl_path path in let (name , path') = simpl_path path in

View File

@ -726,7 +726,7 @@ and type_expression : environment -> ?tv_opt:O.type_value -> I.expression -> O.a
fail @@ not_supported_yet "assign expressions with maps are not supported yet" ae fail @@ not_supported_yet "assign expressions with maps are not supported yet" ae
in in
bind_fold_list aux (typed_name.type_value , []) path in bind_fold_list aux (typed_name.type_value , []) path in
let%bind expr' = type_expression e expr in let%bind expr' = type_expression e ~tv_opt:assign_tv expr in
let t_expr' = get_type_annotation expr' in let t_expr' = get_type_annotation expr' in
let%bind () = let%bind () =
trace_strong (type_error trace_strong (type_error

View File

@ -4,3 +4,12 @@ type foobar is option(int)
const s : foobar = Some(42) const s : foobar = Some(42)
const n : foobar = None const n : foobar = None
function assign (var m : int) : foobar is
var coco : foobar := None;
block
{
coco := Some(m);
coco := None;
}
with coco

View File

@ -369,6 +369,10 @@ let option () : unit result =
let expected = e_typed_none t_int in let expected = e_typed_none t_int in
expect_eq_evaluate program "n" expected expect_eq_evaluate program "n" expected
in in
let%bind () =
let expected = e_typed_none t_int in
expect_eq program "assign" (e_int 12) expected
in
ok () ok ()
let moption () : unit result = let moption () : unit result =