From 0cff93a9085199f12cf1f58a6913f0692c8adf74 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Thu, 30 Oct 2025 15:49:45 +0100 Subject: [PATCH] [hl] restore unsafe cast optimization on Map.get --- src/generators/genhl.ml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index 0e1c473d0f1..9b325fb83a4 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -2325,8 +2325,22 @@ and eval_expr ctx e = ); (match !def_ret with | None -> + let is_map_get_method t = + match follow t with + | TFun (_,rt) -> + (match follow rt with + | TInst({ cl_kind = KTypeParameter ttp; cl_path=["haxe";"ds";("StringMap"|"ObjectMap"|"IntMap"|"Int64Map")],_ }, _) -> true + | _ -> false) + | _ -> + false + in let rt = to_type ctx e.etype in - cast_to ~force:true ctx ret rt e.epos + (match ec.eexpr with + | TField (_, FInstance(_,_,{ cf_kind = Method (MethNormal|MethInline); cf_type = t })) when is_map_get_method t -> + (* let's trust the compiler on map.get type *) + unsafe_cast_to ctx ret rt e.epos + | _ -> + cast_to ~force:true ctx ret rt e.epos) | Some r -> r ) | TField (ec,FInstance({ cl_path = [],"Array" },[t],{ cf_name = "length" })) when to_type ctx t = HDyn ->