@@ -2259,6 +2259,19 @@ let extract_function_name funct =
22592259 | Texp_ident (path , _ , _ ) -> Some (Longident. parse (Path. name path))
22602260 | _ -> None
22612261
2262+ let should_unify_expected_result_before_typing_lowered_apply funct sargs =
2263+ match (extract_function_name funct, sargs) with
2264+ | ( Some (Longident. Ldot (Longident. Lident " Primitive_dict" , " make" )),
2265+ [(Asttypes. Nolabel , {Parsetree. pexp_desc = Parsetree. Pexp_array _})] ) ->
2266+ (* Dict literals *)
2267+ true
2268+ | ( Some
2269+ (Longident. Ldot (Longident. Lident " Primitive_promise" , " unsafe_async" )),
2270+ [(Asttypes. Nolabel , _)] ) ->
2271+ (* Async wrapper *)
2272+ true
2273+ | _ -> false
2274+
22622275type lazy_args =
22632276 (Asttypes .arg_label * (unit -> Typedtree .expression ) option ) list
22642277
@@ -2460,9 +2473,11 @@ and type_expect_ ?deprecated_context ~context ?in_function ?(recarg = Rejected)
24602473 let funct =
24612474 type_exp ~deprecated_context: FunctionCall ~context: None env sfunct
24622475 in
2463- (if Dict_type_helpers. has_dict_literal_attribute sexp.pexp_attributes then
2464- (* Dict literals lower to a regular application, so thread the expected
2465- dict value type into the application before typing the tuple values. *)
2476+ (if should_unify_expected_result_before_typing_lowered_apply funct sargs
2477+ then
2478+ (* Lowered syntax like dict literals and async wrappers becomes a regular
2479+ application, so thread the expected result type into the application
2480+ before typing its arguments. *)
24662481 let _, ty_res =
24672482 filter_arrow ~env
24682483 ~arity: (Some (List. length sargs))
0 commit comments