Browse Source

Escape generated locals with ` again to avoid clash with user vars

Rudy Ges 2 years ago
parent
commit
f586b11e07
2 changed files with 7 additions and 1 deletions
  1. 1 1
      src/context/typecore.ml
  2. 6 0
      src/filters/renameVars.ml

+ 1 - 1
src/context/typecore.ml

@@ -374,7 +374,7 @@ let add_local_with_origin ctx origin n t p =
 	check_local_variable_name ctx n origin p;
 	add_local ctx (VUser origin) n t p
 
-let gen_local_prefix = "_g"
+let gen_local_prefix = "`"
 
 let gen_local ctx t p =
 	add_local ctx VGenerated gen_local_prefix t p

+ 6 - 0
src/filters/renameVars.ml

@@ -358,11 +358,17 @@ and collect_ignore_block ?(in_block=false) rc scope e =
 (**
 	Rename `v` if needed
 *)
+let trailing_numbers = Str.regexp "[0-9]+$"
 let maybe_rename_var rc reserved (v,overlaps) =
 	let commit name =
 		v.v_meta <- (Meta.RealPath,[EConst (String(v.v_name,SDoubleQuotes)),null_pos],null_pos) :: v.v_meta;
 		v.v_name <- name
 	in
+	(* chop escape char for all local variables generated *)
+	if String.unsafe_get v.v_name 0 = String.unsafe_get Typecore.gen_local_prefix 0 then begin
+		let name = String.sub v.v_name 1 (String.length v.v_name - 1) in
+		commit ("_g" ^ (Str.replace_first trailing_numbers "" name))
+	end;
 	let rec loop name count =
 		if StringMap.mem name !reserved || Overlaps.has_name name overlaps then begin
 			let count = count + 1 in