Browse Source

[typer] allow `@:commutative` on non-static functions

closes #5599
Simon Krajewski 7 years ago
parent
commit
f1e00acb63
2 changed files with 17 additions and 1 deletions
  1. 1 1
      src/typing/typer.ml
  2. 16 0
      tests/unit/src/unit/issues/Issue5599.hx

+ 1 - 1
src/typing/typer.ml

@@ -1001,7 +1001,7 @@ and type_binop2 ctx op (e1 : texpr) (e2 : Ast.expr) is_assign_op wt p =
 			| [] ->
 				raise Not_found
 		in
-		loop (if left then a.a_ops else List.filter (fun (_,cf) -> not (Meta.has Meta.Impl cf.cf_meta)) a.a_ops)
+		loop a.a_ops
 	in
 	try
 		begin match follow e1.etype with

+ 16 - 0
tests/unit/src/unit/issues/Issue5599.hx

@@ -0,0 +1,16 @@
+package unit.issues;
+
+private abstract I(Int) from Int to Int {
+    @:op(A==B)
+    @:commutative
+    public function eqString(s:String):Bool
+        return Std.string(this) == s;
+}
+
+class Issue5599 extends unit.Test {
+	function test() {
+        var i:I = 1;
+        t(i == '1');
+        t('1' == i);
+	}
+}