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/.gitignore b/tests/misc/cpp/projects/Issue12027/.gitignore new file mode 100644 index 00000000000..c585e19389d --- /dev/null +++ b/tests/misc/cpp/projects/Issue12027/.gitignore @@ -0,0 +1 @@ +out \ No newline at end of file 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