Browse Source

[php7] fix sum/concat when operand types could not be resolved in compile time

Alexander Kuzmenko 9 years ago
parent
commit
f4731c21f9
2 changed files with 27 additions and 3 deletions
  1. 1 1
      std/php7/Boot.hx
  2. 26 2
      tests/unit/src/unit/TestPhp.hx

+ 1 - 1
std/php7/Boot.hx

@@ -382,7 +382,7 @@ class Boot {
 		Otherwise return sum of `left` and `right`.
 	**/
 	public static function addOrConcat( left:Dynamic, right:Dynamic ) : Dynamic {
-		if ((left.is_string() || left == null) && (right.is_string() || right == null || isNumber(right))) {
+		if (left.is_string() || right.is_string()) {
 			return (left:String) + (right:String);
 		}
 		return Syntax.binop(left, '+', right);

+ 26 - 2
tests/unit/src/unit/TestPhp.hx

@@ -74,11 +74,11 @@ class TestPhp extends Test
 
 		var i = 0;
 		modify(i);
-		eq(10, i);
+		eq(i, 10);
 
 		var d = new DummyForRef();
 		modify(d.getThis().field);
-		eq(10, d.field);
+		eq(d.field, 10);
 	}
 
 	/**
@@ -90,6 +90,30 @@ class TestPhp extends Test
 	// 	modify(i);
 	// 	t(true);
 	// }
+
+	function testAddOrConcat() {
+		var result = add(1, 'a');
+		eq(result, '1a');
+
+		var result = add('a', 1);
+		eq(result, 'a1');
+
+		var result = add('a', 'b');
+		eq(result, 'ab');
+
+		var result = add(1, null);
+		eq(result, 1);
+
+		var result = add(null, 1);
+		eq(result, 1);
+
+		var result = add('a', null);
+		eq(result, 'anull');
+
+		var result = add(null, 'b');
+		eq(result, 'nullb');
+	}
+	function add(a:Dynamic, b:Dynamic):Dynamic return a + b;
 #end
 }