浏览代码

[typer] fix custom array access temp var handling

closes #11248
Simon Krajewski 2 年之前
父节点
当前提交
83b64122ae
共有 2 个文件被更改,包括 24 次插入11 次删除
  1. 6 11
      src/typing/operators.ml
  2. 18 0
      tests/unit/src/unit/issues/Issue11248.hx

+ 6 - 11
src/typing/operators.ml

@@ -704,18 +704,15 @@ let type_assign_op ctx op e1 e2 with_type p =
 		let cf_get,tf_get,r_get,ekey = AbstractCast.find_array_read_access ctx a tl ekey p in
 		(* bind complex keys to a variable so they do not make it into the output twice *)
 		let save = save_locals ctx in
-		let maybe_bind_to_temp e = match Optimizer.make_constant_expression ctx e with
-			| Some e -> e,None
-			| None ->
-				let v = gen_local ctx e.etype p in
-				let e' = mk (TLocal v) e.etype p in
-				e', Some (mk (TVar (v,Some e)) ctx.t.tvoid p)
+		let vr = new value_reference ctx in
+		let maybe_bind_to_temp name e = match Optimizer.make_constant_expression ctx e with
+			| Some e -> e
+			| None -> vr#as_var name e
 		in
-		let ekey,ekey' = maybe_bind_to_temp ekey in
-		let ebase,ebase' = maybe_bind_to_temp ebase in
+		let ebase = maybe_bind_to_temp "base" ebase in
+		let ekey = maybe_bind_to_temp "key" ekey in
 		let eget = mk_array_get_call ctx (cf_get,tf_get,r_get,ekey) c ebase p in
 		let eget = type_binop2 ctx op eget e2 true WithType.value p in
-		let vr = new value_reference ctx in
 		let eget = BinopResult.to_texpr vr eget (fun e -> e) in
 		unify ctx eget.etype r_get p;
 		let cf_set,tf_set,r_set,ekey,eget = AbstractCast.find_array_write_access ctx a tl ekey eget p in
@@ -727,8 +724,6 @@ let type_assign_op ctx op e1 e2 with_type p =
 			| Some _,Some _ ->
 				let ef_set = mk (TField(et,(FStatic(c,cf_set)))) tf_set p in
 				let el = [make_call ctx ef_set [ebase;ekey;eget] r_set p] in
-				let el = match ebase' with None -> el | Some ebase -> ebase :: el in
-				let el = match ekey' with None -> el | Some ekey -> ekey :: el in
 				begin match el with
 					| [e] -> e
 					| el -> mk (TBlock el) r_set p

+ 18 - 0
tests/unit/src/unit/issues/Issue11248.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+class Issue11248 extends unit.Test {
+	public static var BIT_A:UInt = 1;
+	public static var FLAG_1:Int = 0;
+
+	static final _flags:Map<Int, Int> = [0 => 1010];
+	public static var flags(get, never):Map<Int, Int>;
+
+	public static function get_flags() {
+		return _flags;
+	}
+
+	function test() {
+		flags[FLAG_1] ^= BIT_A;
+		eq(1011, flags[FLAG_1]);
+	}
+}