From 6e94ca7c5647de1f34af504f5d3a464e57a97cd6 Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Tue, 4 Mar 2025 06:37:43 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20tmpvar=20redefinition=20when=20incrementi?= =?UTF-8?q?ng=20a=20abstract=20array=20access=20exp=E2=80=A6=20(#12034)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix tmpvar redefinition when incrementing a abstract array access expression involving null coalescing. * Delete redundant .gitignore. --- src/typing/operators.ml | 5 ++++- tests/misc/cpp/projects/Issue12027/Main.hx | 21 +++++++++++++++++++ .../misc/cpp/projects/Issue12027/compile.hxml | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/misc/cpp/projects/Issue12027/Main.hx create mode 100644 tests/misc/cpp/projects/Issue12027/compile.hxml diff --git a/src/typing/operators.ml b/src/typing/operators.ml index 8be57597129..b893dd290aa 100644 --- a/src/typing/operators.ml +++ b/src/typing/operators.ml @@ -984,6 +984,9 @@ let type_unop ctx op flag e with_type p = | AKAccess(a,tl,c,ebase,ekey) -> begin try (match op with Increment | Decrement -> () | _ -> raise Not_found); + let v_base = alloc_var VGenerated "tmp" ebase.etype ebase.epos in + let evar_base = mk (TVar(v_base, Some ebase)) ctx.com.basic.tvoid ebase.epos in + let ebase = mk (TLocal v_base) ebase.etype ebase.epos in let v_key = alloc_var VGenerated "tmp" ekey.etype ekey.epos in let evar_key = mk (TVar(v_key,Some ekey)) ctx.com.basic.tvoid ekey.epos in let ekey = mk (TLocal v_key) ekey.etype ekey.epos in @@ -997,7 +1000,7 @@ let type_unop ctx op flag e with_type p = let e_op = mk (TBinop((if op = Increment then OpAdd else OpSub),ev_get,e_one)) ev_get.etype p in (* set *) let e_set = mk_array_set_call ctx (AbstractCast.find_array_write_access_raise ctx a tl ekey e_op p) c ebase p in - let el = evar_key :: evar_get :: e_set :: (if flag = Postfix then [ev_get] else []) in + let el = evar_base :: evar_key :: evar_get :: e_set :: (if flag = Postfix then [ev_get] else []) in mk (TBlock el) e_set.etype p with Not_found -> let e = mk_array_get_call ctx (AbstractCast.find_array_read_access ctx a tl ekey p) c ebase p in diff --git a/tests/misc/cpp/projects/Issue12027/Main.hx b/tests/misc/cpp/projects/Issue12027/Main.hx new file mode 100644 index 00000000000..418ba8f58b4 --- /dev/null +++ b/tests/misc/cpp/projects/Issue12027/Main.hx @@ -0,0 +1,21 @@ +function main() { + foo(new Foo()); +} + +function foo(foo:Null) { + (foo ?? throw "hello")[0]++; +} + +abstract Foo(Int) { + public function new() { + this = 0; + } + + @:op([]) function get(i:Int) { + return this; + } + + @:op([]) function set(i:Int, val:Int) { + return this; + } +} diff --git a/tests/misc/cpp/projects/Issue12027/compile.hxml b/tests/misc/cpp/projects/Issue12027/compile.hxml new file mode 100644 index 00000000000..cf54a5789e3 --- /dev/null +++ b/tests/misc/cpp/projects/Issue12027/compile.hxml @@ -0,0 +1,2 @@ +-m Main +-cpp out \ No newline at end of file