浏览代码

only check non-@:impl or commutative @:ops for right hand expr (fixes #8790)

Aleksandr Kuzmenko 6 年之前
父节点
当前提交
0f70137038

+ 7 - 1
src/typing/typer.ml

@@ -1017,7 +1017,13 @@ and type_binop2 ?(abstract_overload_only=false) ctx op (e1 : texpr) (e2 : Ast.ex
 			| [] ->
 			| [] ->
 				raise Not_found
 				raise Not_found
 		in
 		in
-		loop a.a_ops
+		if left then
+			loop a.a_ops
+		else
+			let not_impl_or_is_commutative (_, cf) =
+				not (Meta.has Meta.Impl cf.cf_meta) || Meta.has Meta.Commutative cf.cf_meta
+			in
+			loop (List.filter not_impl_or_is_commutative a.a_ops)
 	in
 	in
 	try
 	try
 		begin match follow e1.etype with
 		begin match follow e1.etype with

+ 18 - 0
tests/misc/projects/Issue8790/Main.hx

@@ -0,0 +1,18 @@
+class Main {
+	public static function main() {
+		1 + new Int8(1);
+	}
+}
+
+abstract Int8(Int) {
+
+	public inline function new(value:Int) {
+		this = value;
+	}
+
+	@:op(A + B) function addition(b:Int8):Int8;
+
+	@:op(A + B) static function intAddition(a:Int8, b:Int):Int {
+		return b + cast a;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue8790/compile-fail.hxml

@@ -0,0 +1 @@
+-main Main

+ 1 - 0
tests/misc/projects/Issue8790/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:3: characters 7-18 : Int8 should be Int