Kaynağa Gözat

[typer] respect getter for (get, default) properties

closes #9750
Simon Krajewski 5 yıl önce
ebeveyn
işleme
3b0e07dae9

+ 6 - 4
src/typing/operators.ml

@@ -689,14 +689,16 @@ let type_assign_op ctx op e1 e2 with_type p =
 		)
 	| AKUsingField _ ->
 		error "Invalid operation" p
-	| AKField fa ->
-		let e,vr = process_lhs_expr ctx "fh" (FieldAccess.get_field_expr fa FWrite) in
-		let e_rhs = type_binop2 ctx op e e2 true (WithType.with_type e.etype) p in
-		assign vr e e_rhs
 	| AKExpr e ->
 		let e,vr = process_lhs_expr ctx "lhs" e in
 		let e_rhs = type_binop2 ctx op e e2 true (WithType.with_type e.etype) p in
 		assign vr e e_rhs
+	| AKField fa ->
+		let vr = new value_reference ctx in
+		let ef = vr#get_expr_part "fh" fa.fa_on in
+		let _,e_rhs = field_rhs op fa.fa_field ef in
+		let e_lhs = FieldAccess.get_field_expr {fa with fa_on = ef} FWrite in
+		assign vr e_lhs e_rhs
 	| AKAccessor fa ->
 		let vr = new value_reference ctx in
 		let ef = vr#get_expr_part "fh" fa.fa_on in

+ 3 - 3
tests/optimization/src/issues/Issue9778.hx

@@ -43,7 +43,7 @@ class Issue9778 {
 	@:js('
 		var c = new issues_Issue9778Class();
 		c.set_x(c.get_x() + 1);
-		c.y += 1;
+		c.y = c.get_y() + 1;
 		c.set_z(c.z + 1);
 		c.set_x(c.get_x() + 1);
 		c.y = c.get_y() + 1;
@@ -71,7 +71,7 @@ class Issue9778 {
 		var fh = c.next;
 		fh.set_x(fh.get_x() + 1);
 		var fh = c.next;
-		fh.y += 1;
+		fh.y = fh.get_y() + 1;
 		var fh = c.next;
 		fh.set_z(fh.z + 1);
 		var fh = c.next;
@@ -104,7 +104,7 @@ class Issue9778 {
 	@:js('
 		var c = new issues_Issue9778Class();
 		issues_Issue9778.use(c.set_x(c.get_x() + 1));
-		issues_Issue9778.use(c.y += 1);
+		issues_Issue9778.use(c.y = c.get_y() + 1);
 		issues_Issue9778.use(c.set_z(c.z + 1));
 		issues_Issue9778.use(c.set_x(c.get_x() + 1));
 		issues_Issue9778.use(c.y = c.get_y() + 1);

+ 1 - 1
tests/unit/src/unit/issues/Issue9746.hx

@@ -142,7 +142,7 @@ class Issue9746 extends unit.Test {
 		#else
 		var ctx = new PropertyClassTestContext();
 		eq(2, ctx.get()[ctx.index++].propGet += 2);
-		ctx.check(1, 0 /* TODO: I think this should be 1 */, 0);
+		ctx.check(1, 1, 0);
 		#end
 
 		var ctx = new PropertyClassTestContext();