diff --git a/src/passes/2-simplify/ligodity.ml b/src/passes/2-simplify/ligodity.ml index 92877e722..06928f754 100644 --- a/src/passes/2-simplify/ligodity.ml +++ b/src/passes/2-simplify/ligodity.ml @@ -60,17 +60,6 @@ module Errors = struct ] in error ~data title message - let unsupported_string_catenation expr = - let title () = "string expressions" in - let message () = - Format.asprintf "string concatenation is not supported yet" in - let expr_loc = Raw.expr_to_region expr in - let data = [ - ("expr_loc", - fun () -> Format.asprintf "%a" Location.pp_lift @@ expr_loc) - ] in - error ~data title message - let untyped_fun_param var = let title () = "function parameter" in let message () = @@ -446,8 +435,11 @@ let rec simpl_expression : in return @@ e_literal ~loc (Literal_string s') ) - | EString (Cat _) as e -> - fail @@ unsupported_string_catenation e + | EString (Cat c) -> + let (c, loc) = r_split c in + let%bind string_left = simpl_expression c.arg1 in + let%bind string_right = simpl_expression c.arg2 in + return @@ e_string_cat ~loc string_left string_right | ELogic l -> simpl_logic_expression l | EList l -> simpl_list_expression l | ECase c -> ( diff --git a/src/test/contracts/string_arithmetic.mligo b/src/test/contracts/string_arithmetic.mligo new file mode 100644 index 000000000..89d77ff60 --- /dev/null +++ b/src/test/contracts/string_arithmetic.mligo @@ -0,0 +1,4 @@ +(* Test that the string concatenation syntax in CameLIGO works *) + +let concat_syntax (s: string) = + s ^ "test_literal" diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 7f0b9190a..6a44a8d65 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -203,6 +203,11 @@ let string_arithmetic () : unit result = let%bind () = expect_fail program "slice_op" (e_string "ba") in ok () +let string_arithmetic_mligo () : unit result = + let%bind program = mtype_file "./contracts/string_arithmetic.mligo" in + let%bind () = expect_eq program "concat_syntax" (e_string "string_") (e_string "string_test_literal") + in ok () + let bytes_arithmetic () : unit result = let%bind program = type_file "./contracts/bytes_arithmetic.ligo" in let%bind foo = e_bytes "0f00" in @@ -921,6 +926,7 @@ let main = test_suite "Integration (End to End)" [ test "arithmetic" arithmetic ; test "bitiwse_arithmetic" bitwise_arithmetic ; test "string_arithmetic" string_arithmetic ; + test "string_arithmetic (mligo)" string_arithmetic_mligo ; test "bytes_arithmetic" bytes_arithmetic ; test "set_arithmetic" set_arithmetic ; test "unit" unit_expression ;