Use of ~ for overloaded distribution statements?

While I can successfully overload distribution statements, if I use the ~ syntax instead of target, the compiler throws a syntax error:

functions {
  
  real distribution_lpdf(vector y, real mu, real sigma) {
    return normal_lpdf(y | mu, sigma);
  }
  
  real distribution_lpmf(array[] int y, real pi) {
    return bernoulli_lpmf(y | pi);
  }
  
}

data {
  int N;
  vector[N] y;
}

parameters {
  real mu;
  real<lower=0> sigma;
}

model {
  target += distribution_lpdf(y | mu, sigma); // works fine
  // y ~ distribution(mu, sigma);             // syntax error
}

Is this intended or discussed in the documentation?

What interface to stan are you using (and what version)? The model you posted compiles for me if you uncomment the ~ statement

stan 2.35.0
cmdstanr 0.8.1.9000

So,

m_test <- cmdstan_model('models/test.stan')

What error are you getting specifically?

Some sort of template signature issue:

Compiling Stan program...
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, false, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:93:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, false, double>' requested here
   93 |     return static_cast<const M*>(this)->template log_prob<false, false, double>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__&
 y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, false, Eigen::Matrix<stan::math::var_value<double>, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:98:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, false, stan::math::var_value<double>>' requested here
   98 |     return static_cast<const M*>(this)->template log_prob<false, false>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, true, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:104:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, true, double>' requested here
  104 |     return static_cast<const M*>(this)->template log_prob<false, true>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, true, Eigen::Matrix<stan::math::var_value<double>, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp
:109:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, true, stan::math::var_value<double>>' requested here
  109 |     return static_cast<const M*>(this)->template log_prob<false, true>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
/
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, false, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:115:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, false, double>' requested here
  115 |     return static_cast<const M*>(this)->template log_prob<true, false>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, false, Eigen::Matrix<stan::math::var_value<double>, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:120:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, false, stan::math::var_value<double>>' requested here
  120 |     return static_cast<const M*>(this)->template log_prob<true, false>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, cons
t T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, true, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:126:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, true, double>' requested here
  126 |     return static_cast<const M*>(this)->template log_prob<true, true>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:429:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, true, Eigen::Matrix<stan::math::var_value<double>, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
  429 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:132:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, true, stan::math::var_value<double>>' requested here
  132 |     
return static_cast<const M*>(this)->template log_prob<true, true>(theta,
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, false, std::vector<double>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>(params_r, params
_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:156:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, false, double>' requested here
  156 |     return static_cast<const M*>(this)->template log_prob<false, false>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, false, std::vector<stan::math::var_value<double>>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:162:50:
 note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, false, stan::math::var_value<double>>' requested here
  162 |     return static_cast<const M*>(this)->template log_prob<false, false>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, true, std::vector<double>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:169:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, true, double>' requested here
  169 |     return static_cast<const M*>(this)->template log_prob<false, true>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<false, true, std::vector<stan::math::var_value<double>>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>(para
ms_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:175:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<false, true, stan::math::var_value<double>>' requested here
  175 |     return static_cast<const M*>(this)->template log_prob<false, true>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, false, std::vector<double>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:182:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, false, double>' requested here
  182 |     return static_cast<const M*>(this)->template log_prob<true, false>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostr
eam* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, false, std::vector<stan::math::var_value<double>>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:188:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, false, stan::math::var_value<double>>' requested here
  188 |     return static_cast<const M*>(this)->template log_prob<true, false>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:185:24: error: no matching function for call to 'distribution_lpmf'
  185 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, true, std::vector<double>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, jacobian__>
(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:195:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, true, double>' requested here
  195 |     return static_cast<const M*>(this)->template log_prob<true, true>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:228:24: error: no matching function for call to 'distribution_lpmf'
  228 |         lp_accum__.add(distribution_lpmf<propto__>(y, mu, sigma, pstream__));
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:434:12: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob_impl<true, true, std::vector<stan::math::var_value<double>>, std::vector<int>, nullptr, nullptr, nullptr>' requested here
  434 |     return log_prob_impl<propto__, j
acobian__>(params_r, params_i, pstream);
      |            ^
/Users/scottspencer/.cmdstan/cmdstan-2.35.0/stan/src/stan/model/model_base_crtp.hpp:201:50: note: in instantiation of function template specialization 'test_model_namespace::test_model::log_prob<true, true, stan::math::var_value<double>>' requested here
  201 |     return static_cast<const M*>(this)->template log_prob<true, true>(
      |                                                  ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:92:3: note: in instantiation of member function 'stan::model::model_base_crtp<test_model_namespace::test_model>::log_prob_propto_jacobian' requested here
   92 |   ~test_model() {}
      |   ^
/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.hpp:71:1: note: candidate function template not viable: requires 3 arguments, but 4 were provided
   71 | distribution_lpmf(const T0__& y, const T1__& pi, std::ostream* pstream__) {
      | ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

16 errors generated.

make: *** [/var/folders/ws/8j1fqv252dxfrs1gzry8c46r0000gn/T/Rtmpq4SDpo/model-14e174071601.o] Error 1

Error: An error occured during compilation! See the message above for more information.

The codegen is confused and tries to use the _lpmf version when it should be using the _lpdf.

You can also trigger this bug by overloading a distribution in the math library but then using the original function instead of the overload.

functions {
  real bernoulli_lpmf(int y, real theta, real alpha) {
    return log(theta);
  }
}
data {
  int y;
}
parameters {
  real<lower=0,upper=1> theta;
}
model {
  y ~ bernoulli(theta);
}

Sorry @ssp3nc3r – I thought you were getting an error in the Stan compiler. I can definitely confirm that the c++ goes wrong, and we will fix it

1 Like

@nhuurre – yep. I think the issue is actually in the lowering to the MIR, not code gen – it’s assuming the name doesn’t matter and that C++ will resolve the overload for us, but that’s obviously not true if the “overloads” have different names. One thought is the typechecker could just update Tilde nodes so that their name contains the suffix after typechecking

1 Like

@ssp3nc3r this will be fixed by Fix code generation issue with overloaded distributions in `~` statements by WardBrian · Pull Request #1466 · stan-dev/stanc3 · GitHub, which will be included in the next release of Stan (expected in early December).

Thank you for reporting!

2 Likes