@@ -434,35 +434,34 @@ let check_normal_fn ~is_cond_dist loc tenv id es =
434434 (Env. nearest_ident tenv id.name) )
435435 |> error
436436 | _ (* a function *) -> (
437- let
438- (* NB: At present, [SignatureMismatch.matching_function] cannot handle overloaded function types.
439- This is not needed until UDFs can be higher-order, as it is special cased for
440- variadic functions
441- *)
442- open
443- SignatureMismatch in
444- match matching_function tenv id.name (get_arg_types es) with
445- | UniqueMatch (Void, _ , _ ) ->
446- Semantic_error. returning_fn_expected_nonreturning_found loc id.name
447- |> error
448- | UniqueMatch (ReturnType ut , fnk , promotions ) ->
449- mk_typed_expression
450- ~expr:
451- (mk_fun_app ~is_cond_dist
452- ( fnk (Fun_kind. suffix_from_name id.name)
453- , id
454- , SignatureMismatch. promote es promotions ) )
455- ~ad_level: (expr_ad_lub es) ~type_: ut ~loc
456- | AmbiguousMatch sigs ->
457- Semantic_error. ambiguous_function_promotion loc id.name
458- (Some (List. map ~f: type_of_expr_typed es))
459- sigs
460- |> error
461- | SignatureErrors (l , b ) ->
462- es
463- |> List. map ~f: (fun e -> e.emeta.type_)
464- |> Semantic_error. illtyped_fn_app loc id.name (l, b)
465- |> error )
437+ (* NB: At present, [SignatureMismatch.matching_function] cannot handle overloaded function types.
438+ This is not needed until UDFs can be higher-order, as it is special cased for
439+ variadic functions
440+ *)
441+ match
442+ SignatureMismatch. matching_function tenv id.name (get_arg_types es)
443+ with
444+ | UniqueMatch (Void, _ , _ ) ->
445+ Semantic_error. returning_fn_expected_nonreturning_found loc id.name
446+ |> error
447+ | UniqueMatch (ReturnType ut , fnk , promotions ) ->
448+ mk_typed_expression
449+ ~expr:
450+ (mk_fun_app ~is_cond_dist
451+ ( fnk (Fun_kind. suffix_from_name id.name)
452+ , id
453+ , SignatureMismatch. promote es promotions ) )
454+ ~ad_level: (expr_ad_lub es) ~type_: ut ~loc
455+ | AmbiguousMatch sigs ->
456+ Semantic_error. ambiguous_function_promotion loc id.name
457+ (Some (List. map ~f: type_of_expr_typed es))
458+ sigs
459+ |> error
460+ | SignatureErrors (l , b ) ->
461+ es
462+ |> List. map ~f: (fun e -> e.emeta.type_)
463+ |> Semantic_error. illtyped_fn_app loc id.name (l, b)
464+ |> error )
466465
467466(* * Given a constraint function [matches], find any signature which exists
468467 Returns the first [Ok] if any exist, or else [Error]
@@ -1444,8 +1443,9 @@ and verify_unique_signature tenv loc id arg_tys rt =
14441443 | [] -> ()
14451444 | {type_ = UFun (_ , rt' , _ , _ ); _} :: _ when rt <> rt' ->
14461445 Semantic_error. fn_overload_rt_only loc id.name rt rt' |> error
1447- | _ ->
1446+ | {kind; _} :: _ ->
14481447 Semantic_error. fn_decl_redefined loc id.name
1448+ ~stan_math: (kind = `StanMath )
14491449 (UnsizedType. UFun (arg_tys, rt, Fun_kind. suffix_from_name id.name, AoS ))
14501450 |> error
14511451
0 commit comments