Jelajahi Sumber

fixed inlined locals

Nicolas Cannasse 17 tahun lalu
induk
melakukan
2ed32d772b
2 mengubah file dengan 9 tambahan dan 2 penghapusan
  1. 1 0
      doc/CHANGES.txt
  2. 8 2
      typer.ml

+ 1 - 0
doc/CHANGES.txt

@@ -12,6 +12,7 @@ TODO inlining : substitute class+function type parameters in order to have fully
 	genswf9 : fixed verify error with Null<Class> (was using dynamic access)
 	small patch for jsfl support
 	added __charCodeAt for very fast string operations on Flash9
+	bugfix with inlined local variables
 
 2008-04-05: 1.19
 	fixed flash9 Array.toString

+ 8 - 2
typer.ml

@@ -2254,7 +2254,10 @@ and type_inline ctx f ethis params tret p =
 			{ e with eexpr = TLocal vthis }
 		| TVars vl ->
 			has_vars := true;
-			let vl = List.map (fun (v,t,e) -> local v,t,opt (map false) e) vl in
+			let vl = List.map (fun (v,t,e) ->
+				let e = opt (map false) e in
+				add_local ctx v t,t,e
+			) vl in
 			{ e with eexpr = TVars vl }
 		| TReturn eo ->
 			if not term then error "Cannot inline a not final return" e.epos;
@@ -2272,6 +2275,7 @@ and type_inline ctx f ethis params tret p =
 		| TTry (e1,catches) ->
 			{ e with eexpr = TTry (map term e1,List.map (fun (v,t,e) -> local v,t,map term e) catches) }
 		| TBlock l ->
+			let old = save_locals ctx in
 			let rec loop = function
 				| [] -> []
 				| [e] -> [map term e]
@@ -2279,7 +2283,9 @@ and type_inline ctx f ethis params tret p =
 					let e = map false e in
 					e :: loop l
 			in
-			{ e with eexpr = TBlock (loop l) }
+			let l = loop l in
+			old();
+			{ e with eexpr = TBlock l }
 		| TParenthesis _ | TIf (_,_,Some _) | TSwitch (_,_,Some _) ->
 			Transform.map (map term) e
 		| TConst TSuper ->