Browse Source

fixed issue 847

Franco Ponticelli 13 years ago
parent
commit
b08019e45a
2 changed files with 26 additions and 7 deletions
  1. 18 7
      genphp.ml
  2. 8 0
      std/php/Boot.hx

+ 18 - 7
genphp.ml

@@ -986,13 +986,24 @@ and gen_expr ctx e =
 				gen_value_op ctx e2;
 			)
 		| Ast.OpAssignOp(Ast.OpAdd) when (is_uncertain_expr e1 && is_uncertain_expr e2) ->
-			leftside e1;
-			spr ctx " = ";
-			spr ctx "_hx_add(";
-			gen_value_op ctx e1;
-			spr ctx ", ";
-			gen_value_op ctx e2;
-			spr ctx ")";
+			(match e1.eexpr with
+			| TArray(te1, te2) ->
+				spr ctx "_hx_array_assign($»t1 = ";
+				gen_value ctx te1;
+				spr ctx ", $»t2 = ";
+				gen_value ctx te2;
+				spr ctx ", $»t1->»a[$»t2] + ";
+				gen_value_op ctx e2;
+				spr ctx ")";
+			| _ ->
+				leftside e1;
+				spr ctx " = ";
+				spr ctx "_hx_add(";
+				gen_value_op ctx e1;
+				spr ctx ", ";
+				gen_value_op ctx e2;
+				spr ctx ")";
+			)
 		| Ast.OpAssignOp(Ast.OpAdd) when (is_string_expr e1 || is_string_expr e2) ->
 			leftside e1;
 			spr ctx " .= ";

+ 8 - 0
std/php/Boot.hx

@@ -16,6 +16,14 @@ function _hx_add($a, $b) {
 	}
 }
 
+function _hx_add_assign(&$a, $b) {
+	if (!_hx_is_numeric($a) || !_hx_is_numeric($b)) {
+		return $a .= $b;
+	} else {
+		return $a += $b;
+	}
+}
+
 function _hx_anonymous($arr = array()) {
 	$o = new _hx_anonymous();
 	foreach($arr as $k => $v)