Skip to content

Commit

Permalink
Fix TFor when ctx.allow_transform = false
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz authored and Simn committed Jan 22, 2025
1 parent 8b3bc18 commit 0b2b0da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,11 @@ let rec type_constant_value basic (e,p) =
let is_constant_value basic e =
try (ignore (type_constant_value basic e); true) with Error {err_message = Custom _} -> false

let for_remap basic v e1 e2 p =
let v' = alloc_var v.v_kind v.v_name e1.etype e1.epos in
let ev' = mk (TLocal v') e1.etype e1.epos in
let t1 = (Abstract.follow_with_abstracts e1.etype) in
let ehasnext = mk (TField(ev',try quick_field t1 "hasNext" with Not_found -> raise_typing_error (s_type (print_context()) t1 ^ "has no field hasNext()") p)) (tfun [] basic.tbool) e1.epos in
let for_remap basic v etype e1 e2 p =
let v' = alloc_var v.v_kind v.v_name etype e1.epos in
let ev' = mk (TLocal v') etype e1.epos in
let t1 = (Abstract.follow_with_abstracts etype) in
let ehasnext = mk (TField(ev',try quick_field t1 "hasNext" with Not_found -> raise_typing_error (s_type (print_context()) t1 ^ " has no field hasNext()") p)) (tfun [] basic.tbool) e1.epos in
let ehasnext = mk (TCall(ehasnext,[])) basic.tbool ehasnext.epos in
let enext = mk (TField(ev',quick_field t1 "next")) (tfun [] v.v_type) e1.epos in
let enext = mk (TCall(enext,[])) v.v_type e1.epos in
Expand Down
6 changes: 3 additions & 3 deletions src/typing/forLoop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let optimize_for_loop_iterator ctx v e1 e2 p =
get_class_and_params e1
in
let _, _, fhasnext = (try raw_class_field (fun cf -> apply_params c.cl_params tl cf.cf_type) c tl "hasNext" with Not_found -> raise Exit) in
if fhasnext.cf_kind <> Method MethInline then raise Exit;
if not ctx.allow_inline || fhasnext.cf_kind <> Method MethInline then raise Exit;
let it_type = TInst(c,tl) in
let tmp = gen_local ctx it_type e1.epos in
let eit = mk (TLocal tmp) it_type p in
Expand Down Expand Up @@ -284,7 +284,7 @@ module IterationKind = struct
{
it_kind = it;
it_type = pt;
it_expr = if not ctx.allow_transform then e else e1;
it_expr = e1;
}

let to_texpr ctx v iterator e2 p =
Expand Down Expand Up @@ -414,7 +414,7 @@ module IterationKind = struct
begin try
optimize_for_loop_iterator ctx v e1 e2 p
with Exit ->
Texpr.for_remap ctx.t v e1 e2 p
Texpr.for_remap ctx.t v (ctx.t.titerator pt) e1 e2 p
end
| IteratorGenericStack c ->
let tcell = (try (PMap.find "head" c.cl_fields).cf_type with Not_found -> die "" __LOC__) in
Expand Down

0 comments on commit 0b2b0da

Please sign in to comment.