Browse Source

fixed cast(n,Int) and cast(n,UInt) in flash9 (close #2081)

Nicolas Cannasse 12 years ago
parent
commit
fe667af867
1 changed files with 10 additions and 1 deletions
  1. 10 1
      genswf9.ml

+ 10 - 1
genswf9.ml

@@ -1357,8 +1357,17 @@ let rec gen_expr_content ctx retval e =
 				| KType n when (match n with HMPath ([],"String") -> false | _ -> true) ->
 					(* for normal classes, we can use native cast *)
 					write ctx (HCast tid)
+				| KInt | KUInt ->
+					(* allow any number to be cast to int (will coerce) *)
+					write ctx HDup;
+					write ctx (HIsType (HMPath([],"Number")));
+					let j = jump ctx J3True in
+					write ctx (HString "Class cast error");
+					write ctx HThrow;
+					j();
+					write ctx (HCast tid)
 				| _ ->
-					(* we need to check with "is" first *)
+					(* we need to check with "is" first, to prevent convertion *)
 					write ctx HDup;
 					write ctx (HIsType tid);
 					let j = jump ctx J3True in