Răsfoiți Sursa

[jvm] handle some missing TFloat cases

closes #10965
Simon Krajewski 2 ani în urmă
părinte
comite
29a318d5cf
2 a modificat fișierele cu 43 adăugiri și 0 ștergeri
  1. 4 0
      src/generators/genjvm.ml
  2. 39 0
      tests/unit/src/unit/issues/Issue10965.hx

+ 4 - 0
src/generators/genjvm.ml

@@ -1396,6 +1396,9 @@ class texpr_to_jvm
 				| TDouble ->
 				| TDouble ->
 					code#dconst 1.;
 					code#dconst 1.;
 					if op = Increment then code#dadd else code#dsub
 					if op = Increment then code#dadd else code#dsub
+				| TFloat ->
+					code#fconst 1.;
+					if op = Increment then code#fadd else code#fsub
 				| TByte | TShort | TInt ->
 				| TByte | TShort | TInt ->
 					code#iconst Int32.one;
 					code#iconst Int32.one;
 					if op = Increment then code#iadd else code#isub;
 					if op = Increment then code#iadd else code#isub;
@@ -1412,6 +1415,7 @@ class texpr_to_jvm
 			begin match jsig with
 			begin match jsig with
 			| TLong -> code#lneg;
 			| TLong -> code#lneg;
 			| TDouble -> code#dneg;
 			| TDouble -> code#dneg;
+			| TFloat -> code#fneg;
 			| TByte | TShort | TInt -> code#ineg;
 			| TByte | TShort | TInt -> code#ineg;
 			| _ -> jm#invokestatic haxe_jvm_path "opNeg" (method_sig [object_sig] (Some object_sig))
 			| _ -> jm#invokestatic haxe_jvm_path "opNeg" (method_sig [object_sig] (Some object_sig))
 			end;
 			end;

+ 39 - 0
tests/unit/src/unit/issues/Issue10965.hx

@@ -0,0 +1,39 @@
+package unit.issues;
+
+class Issue10965 extends Test {
+	#if jvm
+	function testNeg() {
+		var a:Single = 1;
+		var c = -a;
+		eq((-1 : Single), c);
+	}
+
+	function testIncPre() {
+		var a:Single = 1;
+		var c = ++a;
+		eq((2 : Single), a);
+		eq((2 : Single), c);
+	}
+
+	function testIncPost() {
+		var a:Single = 1;
+		var c = a++;
+		eq((2 : Single), a);
+		eq((1 : Single), c);
+	}
+
+	function testDecPre() {
+		var a:Single = 1;
+		var c = --a;
+		eq((0 : Single), a);
+		eq((0 : Single), c);
+	}
+
+	function testDecPost() {
+		var a:Single = 1;
+		var c = a--;
+		eq((0 : Single), a);
+		eq((1 : Single), c);
+	}
+	#end
+}