diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index 214daaafe..44c6c0734 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -406,9 +406,7 @@ and lhs = Path of path | MapPath of map_lookup reg -and rhs = - Expr of expr -| NoneExpr of c_None +and rhs = expr and loop = While of while_loop reg @@ -758,9 +756,7 @@ let lhs_to_region : lhs -> Region.t = function Path path -> path_to_region path | MapPath {region; _} -> region -let rhs_to_region = function - Expr e -> expr_to_region e -| NoneExpr r -> r +let rhs_to_region = expr_to_region let selection_to_region = function FieldName {region; _} diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index 15e7e9883..4984830e0 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -390,9 +390,7 @@ and lhs = Path of path | MapPath of map_lookup reg -and rhs = - Expr of expr -| NoneExpr of c_None +and rhs = expr and loop = While of while_loop reg diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index a1902bade..bc99f9176 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -591,7 +591,7 @@ assignment: in {region; value}} rhs: - expr { Expr $1 } + expr { $1 } lhs: path { Path $1 } diff --git a/src/passes/1-parser/pascaligo/ParserLog.ml b/src/passes/1-parser/pascaligo/ParserLog.ml index 4c8223aab..3be60d699 100644 --- a/src/passes/1-parser/pascaligo/ParserLog.ml +++ b/src/passes/1-parser/pascaligo/ParserLog.ml @@ -309,9 +309,7 @@ and print_assignment {value; _} = print_token assign ":="; print_rhs rhs -and print_rhs = function - Expr e -> print_expr e -| NoneExpr r -> print_token r "None" +and print_rhs e = print_expr e and print_lhs = function Path path -> print_path path diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index 022577c91..44dd0afda 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -26,16 +26,6 @@ module Errors = struct ] in 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 title () = "bad bytes string" in let message () = @@ -793,10 +783,7 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu ) | Assign a -> ( let (a , loc) = r_split a in - let%bind value_expr = match a.rhs with - | Expr e -> simpl_expression e - | NoneExpr reg -> fail @@ unsupported_ass_None reg - in + let%bind value_expr = simpl_expression a.rhs in match a.lhs with | Path path -> ( let (name , path') = simpl_path path in diff --git a/src/passes/4-typer/typer.ml b/src/passes/4-typer/typer.ml index 391239506..28258b9fb 100644 --- a/src/passes/4-typer/typer.ml +++ b/src/passes/4-typer/typer.ml @@ -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 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%bind () = trace_strong (type_error diff --git a/src/test/contracts/option.ligo b/src/test/contracts/option.ligo index c2d36439d..d3d1ef36c 100644 --- a/src/test/contracts/option.ligo +++ b/src/test/contracts/option.ligo @@ -4,3 +4,12 @@ type foobar is option(int) const s : foobar = Some(42) const n : foobar = None + +function assign (var m : int) : foobar is + var coco : foobar := None; + block +{ + coco := Some(m); + coco := None; +} +with coco diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index b7fae8c0b..a8f67cd2b 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -369,6 +369,10 @@ let option () : unit result = let expected = e_typed_none t_int in expect_eq_evaluate program "n" expected in + let%bind () = + let expected = e_typed_none t_int in + expect_eq program "assign" (e_int 12) expected + in ok () let moption () : unit result =