Skip to content

Commit a548c5a

Browse files
authored
[hl] restore unsafe cast optimization on Map.get (#12396)
1 parent 6d5e23c commit a548c5a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/generators/genhl.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,8 +2328,22 @@ and eval_expr ctx e =
23282328
);
23292329
(match !def_ret with
23302330
| None ->
2331+
let is_map_get_method t =
2332+
match follow t with
2333+
| TFun (_,rt) ->
2334+
(match follow rt with
2335+
| TInst({ cl_kind = KTypeParameter ttp; cl_path=["haxe";"ds";("StringMap"|"ObjectMap"|"IntMap"|"Int64Map")],_ }, _) -> true
2336+
| _ -> false)
2337+
| _ ->
2338+
false
2339+
in
23312340
let rt = to_type ctx e.etype in
2332-
cast_to ~force:true ctx ret rt e.epos
2341+
(match ec.eexpr with
2342+
| TField (_, FInstance(_,_,{ cf_kind = Method (MethNormal|MethInline); cf_type = t })) when is_map_get_method t ->
2343+
(* let's trust the compiler on map.get type *)
2344+
unsafe_cast_to ctx ret rt e.epos
2345+
| _ ->
2346+
cast_to ~force:true ctx ret rt e.epos)
23332347
| Some r -> r
23342348
)
23352349
| TField (ec,FInstance({ cl_path = [],"Array" },[t],{ cf_name = "length" })) when to_type ctx t = HDyn ->

0 commit comments

Comments
 (0)