Ver Fonte

[php] fix comparison (closes #4695)

Simon Krajewski há 9 anos atrás
pai
commit
1abdd8abff
3 ficheiros alterados com 35 adições e 5 exclusões
  1. 5 3
      genphp.ml
  2. 3 2
      std/php/_std/Sys.hx
  3. 27 0
      tests/unit/src/unit/issues/Issue4695.hx

+ 5 - 3
genphp.ml

@@ -1225,11 +1225,13 @@ and gen_expr ctx e =
 				let tmp = define_local ctx "_t" in
 				print ctx "(is_object($%s = " tmp;
 				gen_field_op ctx e1;
-				print ctx ") && !($%s instanceof Enum) ? $%s%s" tmp tmp s_phop;
+				print ctx ") && ($%s instanceof Enum) ? $%s%s" tmp tmp s_op;
 				gen_field_op ctx e2;
-				print ctx " : $%s%s" tmp s_op;
+				print ctx " : ";
+				if op = Ast.OpNotEq then spr ctx "!";
+				print ctx "_hx_equal($%s, " tmp;
 				gen_field_op ctx e2;
-				spr ctx ")";
+				spr ctx "))";
 			end
 		| Ast.OpGt | Ast.OpGte | Ast.OpLt | Ast.OpLte when is_string_expr e1 ->
 			spr ctx "(strcmp(";

+ 3 - 2
std/php/_std/Sys.hx

@@ -35,7 +35,8 @@
 	}
 
 	public static function getEnv( s : String ) : String {
-		return untyped __call__("getenv", s);
+		var ret:Dynamic = untyped __call__("getenv", s);
+		return ret == false ? null : ret;
 	}
 
 	public static function putEnv( s : String, v : String ) : Void {
@@ -134,4 +135,4 @@
 		return v;
 	}
 
-}
+}

+ 27 - 0
tests/unit/src/unit/issues/Issue4695.hx

@@ -0,0 +1,27 @@
+package unit.issues;
+
+class Issue4695 extends unit.Test {
+
+	function eqCheck<T>(v1:T, v2:T) {
+		return v1 == v2;
+	}
+	
+	public function testNull() {
+		f("" == null);
+		f(eqCheck("", null));
+		#if !(cpp || flash9 || as3 || java || cs)
+		f(false == null);
+		f(eqCheck(false, null));
+		#end
+	}
+	
+	#if php
+	public function testNativeArray() {
+		var a1 = (untyped __php__)('array("f1" => 1, "f2" => 2, "f3" => 3)');
+		var a2 = (untyped __php__)('array("f1" => true, "f2" => "2", "f3" => 3)');
+		f(a1 == a2);
+		f(eqCheck(a1, a2));
+	}
+	#end
+	
+}