Browse Source

[java] Make Int64 behaviour more consistent. Closes #2752 . Closes #3203

Cauê Waneck 11 years ago
parent
commit
4db79ff81b
4 changed files with 51 additions and 3 deletions
  1. 3 3
      genjava.ml
  2. 14 0
      tests/unit/TestInt64.hx
  3. 15 0
      tests/unit/issues/Issue2752.hx
  4. 19 0
      tests/unit/issues/Issue3203.hx

+ 3 - 3
genjava.ml

@@ -100,12 +100,11 @@ let is_bool t =
 
 let is_int_float gen t =
 	match follow (gen.greal_type t) with
-		| TInst( { cl_path = (["haxe"], "Int64") }, [] )
 		| TInst( { cl_path = (["haxe"], "Int32") }, [] )
 		| TInst( { cl_path = ([], "Int") }, [] ) | TAbstract( { a_path =	([], "Int") }, [] )
 		| TInst( { cl_path = ([], "Float") }, [] ) | TAbstract( { a_path =	([], "Float") }, [] ) ->
 			true
-		| (TAbstract _ as t) when like_float t -> true
+		| (TAbstract _ as t) when like_float t && not (like_i64 t)-> true
 		| _ -> false
 
 let parse_explicit_iface =
@@ -786,6 +785,7 @@ let configure gen =
 	let fn_cl = get_cl (get_type gen (["haxe";"lang"],"Function")) in
 
 	let runtime_cl = get_cl (get_type gen (["haxe";"lang"],"Runtime")) in
+	let nulltdef = get_tdef (get_type gen ([],"Null")) in
 
 	(*let string_ref = get_cl ( get_type gen (["haxe";"lang"], "StringRefl")) in*)
 
@@ -829,7 +829,7 @@ let configure gen =
 									| TAbstract ({ a_path = ["java"],"Char16" },[])
 									| TType ({ t_path = [],"Single" },[])
 									| TAbstract ({ a_path = [],"Single" },[]) ->
-											basic.tnull f_t
+										TType(nulltdef, [f_t])
 									(*| TType ({ t_path = [], "Null"*)
 									| TInst (cl, ((_ :: _) as p)) when cl.cl_path <> (["java"],"NativeArray") ->
 										TInst(cl, List.map (fun _ -> t_dynamic) p)

+ 14 - 0
tests/unit/TestInt64.hx

@@ -22,6 +22,20 @@ class TestInt64 extends Test {
 		eq(Int64.ofInt(0).toStr(), "0");
 	}
 
+	public function testCapture()
+	{
+		var a = Int64.make(0xFF00FF00,0xF0F0F0F0),
+		    b = Int64.make(0xFF00FF00,0xF0F0F0F0);
+		eq(a.compare(b), 0);
+		eq(a.getHigh(), 0xFF00FF00);
+		function test() return Int64.compare(a,Int64.make(0xFF00FF00,0xF0F0F0F0));
+		eq(test(),0);
+		function testSet(v:Int64) b = v;
+		testSet( make(0xFF00FF00, 0xFF0) );
+		eq(b.compare(make(0xFF00FF00,0xFF0)),0);
+		eq(b.getHigh(), 0xFF00FF00);
+	}
+
 	public function testMath() {
 		var a = Int64.make(0, 0x239B0E13);
 		var b = Int64.make(0, 0x39193D1B);

+ 15 - 0
tests/unit/issues/Issue2752.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+import haxe.Int64;
+using haxe.Int64;
+
+class Issue2752 extends Test {
+	function test() {
+		var big : Int64 = Int64.make(2000,1000);
+		var call = function(){
+			eq(big.getHigh(),2000);
+			eq(big.getLow(),1000);
+		}
+		call();
+	}
+}
+

+ 19 - 0
tests/unit/issues/Issue3203.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+import haxe.Int64;
+using haxe.Int64;
+
+class Issue3203 extends Test {
+	function test() {
+		var i64 = I64(Int64.make(1,2));
+		switch (i64) {
+			case I64(x):
+				eq(x.getHigh(),1);
+				eq(x.getLow(),2);
+		}
+	}
+}
+
+private enum Int64Test
+{
+	I64(i:Int64);
+}