Browse Source

rename conflicting slot names (now occur quite often with callback inlining)

Nicolas Cannasse 13 years ago
parent
commit
8d80b758d1
1 changed files with 13 additions and 2 deletions
  1. 13 2
      genswf9.ml

+ 13 - 2
genswf9.ml

@@ -408,12 +408,23 @@ let define_local ctx ?(init=false) v p =
 			let topt = type_opt ctx t in
 			let pos = (try
 				let slot , _ , t = (List.find (fun (_,x,_) -> name = x) ctx.block_vars) in
-				if t <> topt then error ("Local variable '" ^ name ^ "' captured with same name but different types") p;
+				if t <> topt then begin
+					(* we need to rename it since slots are accessed on a by-name basis *)
+					let rec rename i =
+						let name = name ^ string_of_int i in
+						if List.exists (fun(_,x,_) -> name = x) ctx.block_vars then
+							rename (i + 1)
+						else
+							v.v_name <- name
+					in
+					rename 1;
+					raise Not_found
+				end;
 				slot
 			with
 				Not_found ->
 					let n = List.length ctx.block_vars + 1 in
-					ctx.block_vars <- (n,name,topt) :: ctx.block_vars;
+					ctx.block_vars <- (n,v.v_name,topt) :: ctx.block_vars;
 					n
 			) in
 			LScope pos