Browse Source

[jvm] fix `!=` for `Null<Float>` and `Null<Int>` (closes #9897)

Aleksandr Kuzmenko 4 years ago
parent
commit
b7d4a1d0ba
2 changed files with 19 additions and 1 deletions
  1. 8 1
      src/generators/genjvm.ml
  2. 11 0
      tests/unit/src/unit/issues/Issue9897.hx

+ 8 - 1
src/generators/genjvm.ml

@@ -1032,7 +1032,14 @@ class texpr_to_jvm gctx (jc : JvmClass.builder) (jm : JvmMethod.builder) (return
 						(fun () ->
 						(fun () ->
 							jm#get_code#pop;
 							jm#get_code#pop;
 							self#texpr rvalue_any e2;
 							self#texpr rvalue_any e2;
-							self#boolop (CmpSpecial (jm#get_code#if_nonnull sig2))
+							match op with
+							| CmpEq | CmpGe | CmpLe ->
+								self#boolop (CmpSpecial (jm#get_code#if_nonnull sig2))
+							| CmpNe ->
+								self#boolop (CmpSpecial (jm#get_code#if_null sig2))
+							| _ ->
+								jm#get_code#pop;
+								jm#get_code#bconst false
 						)
 						)
 						(fun () ->
 						(fun () ->
 							jm#cast ~not_null:true cast_type;
 							jm#cast ~not_null:true cast_type;

+ 11 - 0
tests/unit/src/unit/issues/Issue9897.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue9897 extends unit.Test {
+	static var nullValue:Null<Float> = null;
+	static var floatValue:Null<Float> = 100;
+
+	function test() {
+		t(nullValue != floatValue);
+		t(floatValue != nullValue);
+	}
+}