diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index 31e739f36..022577c91 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -488,8 +488,11 @@ let rec simpl_expression (t:Raw.expr) : expr result = String.(sub s 1 (length s - 2)) in return @@ e_literal ~loc (Literal_string s') - | EString (Cat _) as e -> - fail @@ unsupported_string_catenation e + | EString (Cat bo) -> + let (bo , loc) = r_split bo in + let%bind sl = simpl_expression bo.arg1 in + let%bind sr = simpl_expression bo.arg2 in + return @@ e_string_cat ~loc sl sr | ELogic l -> simpl_logic_expression l | EList l -> simpl_list_expression l | ESet s -> simpl_set_expression s diff --git a/src/stages/ast_simplified/combinators.ml b/src/stages/ast_simplified/combinators.ml index 8e9e6c377..d50df9ba1 100644 --- a/src/stages/ast_simplified/combinators.ml +++ b/src/stages/ast_simplified/combinators.ml @@ -73,6 +73,7 @@ let e_record ?loc map : expression = location_wrap ?loc @@ E_record map let e_tuple ?loc lst : expression = location_wrap ?loc @@ E_tuple lst let e_some ?loc s : expression = location_wrap ?loc @@ E_constant ("SOME", [s]) let e_none ?loc () : expression = location_wrap ?loc @@ E_constant ("NONE", []) +let e_string_cat ?loc sl sr : expression = location_wrap ?loc @@ E_constant ("CONCAT" , [sl ; sr ]) let e_map_add ?loc k v old : expression = location_wrap ?loc @@ E_constant ("MAP_ADD" , [k ; v ; old]) let e_map ?loc lst : expression = location_wrap ?loc @@ E_map lst let e_set ?loc lst : expression = location_wrap ?loc @@ E_set lst diff --git a/src/test/contracts/string.ligo b/src/test/contracts/string.ligo index ae54f8c09..846daf7e5 100644 --- a/src/test/contracts/string.ligo +++ b/src/test/contracts/string.ligo @@ -1 +1,3 @@ const s : string = "toto" +const x : string = s^"bar" +const y : string = "foo"^x diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 16a4c7d69..b7fae8c0b 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -262,7 +262,8 @@ let unit_expression () : unit result = let string_expression () : unit result = let%bind program = type_file "./contracts/string.ligo" in - expect_eq_evaluate program "s" (e_string "toto") + let%bind _ = expect_eq_evaluate program "s" (e_string "toto") in + expect_eq_evaluate program "y" (e_string "foototobar") let include_ () : unit result = let%bind program = type_file "./contracts/includer.ligo" in