Browse Source

make sure OpAssignOp abstract operator overload variables are declared (closes #5540)

Simon Krajewski 9 years ago
parent
commit
e32f5f1d6f
2 changed files with 23 additions and 1 deletions
  1. 7 1
      src/typing/typer.ml
  2. 16 0
      tests/unit/src/unit/issues/Issue5540.hx

+ 7 - 1
src/typing/typer.ml

@@ -2044,7 +2044,13 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 			| _ ->
 				(* this must be an abstract cast *)
 				check_assign ctx e;
-				eop)
+				if has_side_effect then
+					mk (TBlock [
+						mk (TVar(v,Some e)) ctx.t.tvoid eop.epos;
+						eop
+					]) eop.etype eop.epos
+				else
+					eop)
 		| AKSet (e,t,cf) ->
 			let l = save_locals ctx in
 			let v = gen_local ctx e.etype e.epos in

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

@@ -0,0 +1,16 @@
+package unit.issues;
+
+class Issue5540 extends unit.Test {
+	function test() {
+		eq(1, get().propertySet -= 1);
+	}
+
+	static function get() return { propertySet:new Signal(2) };
+}
+
+private abstract Signal(Int) {
+	public function new(i) this = i;
+
+	@:op(A -= B)
+	public function opRemove(i:Int) return this - i;
+}