@@ -393,9 +393,45 @@ let check_fn ~is_cond_dist loc tenv id es =
393393 (Stan_math_signatures. is_stan_math_function_name
394394 (Utils. normalized_name id.name)) ->
395395 Semantic_error. returning_fn_expected_nonfn_found loc id.name |> error
396- | [] ->
397- Semantic_error. returning_fn_expected_undeclaredident_found loc id.name
398- |> error
396+ | [] -> (
397+ let gen_prefix l = String. concat ~sep: " _" (List. rev l) in
398+ match List. rev (String. split id.name ~on: '_' ) with
399+ | ((" lpmf" | " lupmf" ) as suffix) :: tl
400+ when Utils. is_distribution_name
401+ (String. concat ~sep: " _" (List. rev tl @ [" lpdf" ])) ->
402+ Semantic_error. returning_fn_expected_wrong_dist_suffix_found loc
403+ (gen_prefix tl, suffix)
404+ |> error
405+ | ((" lpdf" | " lupdf" ) as suffix) :: tl
406+ when Utils. is_distribution_name
407+ (String. concat ~sep: " _" (List. rev tl @ [" lpmf" ])) ->
408+ Semantic_error. returning_fn_expected_wrong_dist_suffix_found loc
409+ (gen_prefix tl, suffix)
410+ |> error
411+ | suffix :: tl
412+ when List. mem Utils. cumulative_distribution_suffices_w_rng suffix
413+ ~equal: String. equal ->
414+ let prefix = gen_prefix tl in
415+ let known_families =
416+ List. map
417+ ~f: (fun (_ , y , _ , _ ) -> y)
418+ Stan_math_signatures. distributions
419+ in
420+ let is_known_family s =
421+ List. mem known_families s ~equal: String. equal
422+ in
423+ if is_known_family prefix then
424+ Semantic_error. returning_fn_expected_undeclared_dist_suffix_found
425+ loc (prefix, suffix)
426+ |> error
427+ else
428+ Semantic_error. returning_fn_expected_undeclaredident_found loc
429+ id.name
430+ |> error
431+ | _ ->
432+ Semantic_error. returning_fn_expected_undeclaredident_found loc
433+ id.name
434+ |> error )
399435 | _ (* a function *) -> (
400436 match SignatureMismatch. returntype tenv id.name (get_arg_types es) with
401437 | Ok (Void, _ ) ->
0 commit comments