Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tmpvar redefinition when incrementing a abstract array access exp… #12034

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/misc/cpp/projects/Issue12027/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function main() {
foo(new Foo());
}

function foo(foo:Null<Foo>) {
(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;
}
}
2 changes: 2 additions & 0 deletions tests/misc/cpp/projects/Issue12027/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-m Main
-cpp out
Loading