Browse Source

continue bugfix

Nicolas Cannasse 17 năm trước cách đây
mục cha
commit
35f7c81a34
1 tập tin đã thay đổi với 6 bổ sung4 xóa
  1. 6 4
      typer.ml

+ 6 - 4
typer.ml

@@ -2064,7 +2064,7 @@ and optimize_for_loop ctx i e1 e2 p =
 		let i = add_local ctx i t_int in
 		let i = add_local ctx i t_int in
 		let ident = mk (TLocal i) t_int p in
 		let ident = mk (TLocal i) t_int p in
 		let incr = mk (TUnop (Increment,Prefix,ident)) t_int p in
 		let incr = mk (TUnop (Increment,Prefix,ident)) t_int p in
-		let rec check e =
+		let rec check cont e =
 			match e.eexpr with
 			match e.eexpr with
 			| TBinop (OpAssign,{ eexpr = TLocal l },_)
 			| TBinop (OpAssign,{ eexpr = TLocal l },_)
 			| TBinop (OpAssignOp _,{ eexpr = TLocal l },_)
 			| TBinop (OpAssignOp _,{ eexpr = TLocal l },_)
@@ -2073,12 +2073,14 @@ and optimize_for_loop ctx i e1 e2 p =
 				error "Loop variable cannot be modified" e.epos				
 				error "Loop variable cannot be modified" e.epos				
 			| TFunction f when List.exists (fun (l,_,_) -> l = i) f.tf_args ->
 			| TFunction f when List.exists (fun (l,_,_) -> l = i) f.tf_args ->
 				e
 				e
-			| TContinue ->
+			| TContinue when cont ->
 				mk (TBlock [incr;e]) e.etype e.epos
 				mk (TBlock [incr;e]) e.etype e.epos
+			| TWhile _ | TFor _ ->
+				Transform.map (check false) e
 			| _ ->
 			| _ ->
-				Transform.map check e
+				Transform.map (check cont) e
 		in
 		in
-		let e2 = check (type_expr ~need_val:false ctx e2) in
+		let e2 = check true (type_expr ~need_val:false ctx e2) in
 		let block = match e2.eexpr with
 		let block = match e2.eexpr with
 			| TBlock el -> mk (TBlock (el@[incr])) t_void e2.epos
 			| TBlock el -> mk (TBlock (el@[incr])) t_void e2.epos
 			| _ -> mk (TBlock [e2;incr]) t_void p
 			| _ -> mk (TBlock [e2;incr]) t_void p