Browse Source

[java/cs] Use the typed type for dynamic Neg unop operations

If a dynamic is set instead, use `Float` as the default type
Caue Waneck 7 years ago
parent
commit
ccb65c1076
2 changed files with 22 additions and 1 deletions
  1. 9 1
      src/codegen/gencommon/dynamicOperators.ml
  2. 13 0
      tests/unit/src/unit/issues/Issue6587.hx

+ 9 - 1
src/codegen/gencommon/dynamicOperators.ml

@@ -166,7 +166,15 @@ let init com handle_strings (should_change:texpr->bool) (equals_handler:texpr->t
 			mk (TBlock block) etype e.epos
 
 	| TUnop (op, flag, e1) when should_change e ->
-		let etype = match op with Not -> com.basic.tbool | _ -> com.basic.tint in
+		let etype = match op with
+			| Not -> com.basic.tbool
+			| Neg ->
+				if like_float e.etype || like_i64 e.etype then
+					e.etype
+				else
+					com.basic.tfloat
+			| _ -> com.basic.tint
+		in
 		mk_parent (mk (TUnop (op, flag, mk_cast etype (run e1))) etype e.epos)
 
 	| _ ->

+ 13 - 0
tests/unit/src/unit/issues/Issue6587.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue6587 extends Test {
+  static var consts = {
+		friction: 0.5
+	}
+
+	function test() {
+    f(0 == -consts.friction);
+    var value = -consts.friction;
+    eq(value, -0.5);
+	}
+}