Browse Source

restrict to == and !=

Simon Krajewski 3 days ago
parent
commit
86fe65e4e4
2 changed files with 5 additions and 34 deletions
  1. 5 5
      src/typing/operators.ml
  2. 0 29
      tests/unit/src/unit/issues/Issue12444.hx

+ 5 - 5
src/typing/operators.ml

@@ -480,20 +480,20 @@ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op p =
 						let make e1 e2 = make op_cf cf e1 e2 tret in
 						let t1 = if is_impl then Abstract.follow_with_abstracts t1 else t1 in
 						let check_nullable e t =
-							if is_nullable e.etype <> is_nullable t then raise (Unify_error [])
-							in
+							if is_nullable e.etype <> is_nullable t then raise (Unify_error []);
+						in
 						let e1,e2 = if left || not left && swapped then begin
 							Type.type_eq EqDoNotFollowNull (if is_impl then Abstract.follow_with_abstracts e1.etype else e1.etype) t1;
 							let e2 = AbstractCast.cast_or_unify_raise ctx t2 e2 p in
-							check_nullable e2 t2;
+							if is_eq_op then check_nullable e2 t2;
 							e1,e2
 						end else begin
 							Type.type_eq EqDoNotFollowNull e2.etype t2;
 							let e1 = AbstractCast.cast_or_unify_raise ctx t1 e1 p in
-							check_nullable e1 t1;
+							if is_eq_op then check_nullable e1 t1;
 							e1,e2
 						end in
-						let check_null e t = if is_eq_op then match e.eexpr with
+						let check_null e t = match e.eexpr with
 							| TConst TNull when not (is_explicit_null t) -> raise (Unify_error [])
 							| _ -> ()
 						in

+ 0 - 29
tests/unit/src/unit/issues/Issue12444.hx

@@ -34,26 +34,6 @@ private abstract NotInt64(Int) {
 	@:op(A != B) public static function neqYesYes(a:Null<NotInt64>, b:Null<NotInt64>):String {
 		return "neqYesYes";
 	}
-
-	@:commutative @:op(A + B) public static function plusNoNo(a:NotInt64, b:Int):String {
-		return "plusNoNo";
-	}
-
-	@:commutative @:op(A + B) public static function plusYesNo(a:Null<NotInt64>, b:Int):String {
-		return "plusYesNo";
-	}
-
-	@:commutative @:op(A + B) public static function plusNoYes(a:NotInt64, b:Null<Int>):String {
-		return "plusNoYes";
-	}
-
-	@:commutative @:op(A + B) public static function plusYesYes(a:Null<NotInt64>, b:Null<Int>):String {
-		return "plusYesYes";
-	}
-
-	public inline function get() {
-		return this;
-	}
 }
 
 class Issue12444 extends Test {
@@ -72,14 +52,5 @@ class Issue12444 extends Test {
 		eq("neqYesNo", nullable != notNullable);
 		eq("neqNoYes", notNullable != nullable);
 		eq("neqNoNo", notNullable != notNullable);
-		// + with @:commutative
-		eq("plusYesYes", nullable + nullableInt);
-		eq("plusYesYes", nullableInt + nullable);
-		eq("plusYesNo", nullable + notNullableInt);
-		eq("plusYesNo", notNullableInt + nullable);
-		eq("plusNoYes", notNullable + nullableInt);
-		eq("plusNoYes", nullableInt + notNullable);
-		eq("plusNoNo", notNullable + notNullableInt);
-		eq("plusNoNo", notNullableInt + notNullable);
 	}
 }