From 8ae9701a4f80ef069d5db959529d88f3b76079c6 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Fri, 5 Apr 2024 15:25:46 +0200 Subject: [PATCH] Fix python name clash printing again, for non-ascii --- compiler/scalc/to_python.ml | 6 +++--- tests/backends/python_name_clash.catala_en | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/scalc/to_python.ml b/compiler/scalc/to_python.ml index 17eb0984..0e9f4c97 100644 --- a/compiler/scalc/to_python.ml +++ b/compiler/scalc/to_python.ml @@ -151,7 +151,7 @@ let format_name_cleaned (fmt : Format.formatter) (s : string) : unit = let string_counter_map : int IntMap.t StringMap.t ref = ref StringMap.empty let format_var (fmt : Format.formatter) (v : VarName.t) : unit = - let v_str = Mark.remove (VarName.get_info v) in + let v_str = clean_name (Mark.remove (VarName.get_info v)) in let hash = VarName.hash v in let local_id = match StringMap.find_opt v_str !string_counter_map with @@ -170,8 +170,8 @@ let format_var (fmt : Format.formatter) (v : VarName.t) : unit = in if v_str = "_" then Format.fprintf fmt "_" (* special case for the unit pattern *) - else if local_id = 0 then format_name_cleaned fmt v_str - else Format.fprintf fmt "%a_%d" format_name_cleaned v_str local_id + else if local_id = 0 then Format.pp_print_string fmt v_str + else Format.fprintf fmt "%s_%d" v_str local_id let format_path ctx fmt p = match List.rev p with diff --git a/tests/backends/python_name_clash.catala_en b/tests/backends/python_name_clash.catala_en index 1a5108ce..644f9fb3 100644 --- a/tests/backends/python_name_clash.catala_en +++ b/tests/backends/python_name_clash.catala_en @@ -2,18 +2,18 @@ This test exposes a name clash between the scope function (`ScopeName,` rewritten to `scope_name`) and the scope variable `scope_name`. ```catala -declaration scope SomeName: +declaration scope SomeNâme: input i content integer output o content integer -scope SomeName: +scope SomeNâme: definition o equals i + 1 declaration scope B: - output some_name scope SomeName + output some_nâme scope SomeNâme scope B: - definition some_name.i equals 1 + definition some_nâme.i equals 1 ``` ```catala-test-inline