How to interpret "A returning function was expected but an undeclared identifier '' was supplied"

I am trying to construct a Bayesian model in which the three priors are all defined by given parameters of a user-defined lpdf function. That function is syntactically correct but when I try to check the whole model I get the error above which I find hard to interpret.

Here is my code

functions {
  
  real gpoispoint_lpdf(vector y, real mu, real k, real sigma, real u, real noy) {
    // generalised Pareto log pdf
    int N = rows(y);
    real inv_k = inv(k);
    if (k<0 && max(y-mu)/sigma > -inv_k){
      reject("k<0 and max(y-mu)/sigma > -1/k; found k, sigma =",
      k, sigma);
    }
    if (sigma<=0){
      reject("sigma<=0; found sigma =", sigma);
    }
    if (abs(k) > 1e-15)
    return -(1+inv_k)*sum(log1p((y-mu) * (k/sigma))) - N * log(sigma) -
    noy * (1 + k * (u - mu) / sigma) ^ -inv_k;
    else
    return -sum(y-mu)/sigma - N * log(sigma) -
    (noy * exp(u - mu) / sigma); // limit k->0
  } 
  real minpdf( real z, real[,] v){
    real result;
    for (j in 1:4) {
      if (z <= v[j + 1, 1]){ 
        result = v[j, 2] + 
        (v[j + 1,2]-v[j, 2]) * (z-v[j, 1]) / (v[j + 1, 1]-v[j, 1]); 
        break;
      }  
    } 
    return(result);
  }
  
  real minknot_lpdf(vector y, real a, real b, real t1, real t2, real w){
    int N = rows(y);
    array[5,2] real v;
    real A;
    real B;
    real T1;
    real T2;
    real W;
    real C;
    real D;
    real E; 
    vector[N] f;
    int k;
    v[1, 1] = a;
    v[5, 1] = b;
    v[1, 2] = 0;
    v[5, 2] = 0;
    if (w < t1) {
      A = t1 - a;
      B = t1 - w;
      C = t2 - t1;
      D = b - t2; 
      T1 = (2.0/3.0) * (1/C - 1/D);
      T2 = (2.0/3.0) * (1/D);
      W = (2.0/3.0) * (1 - (B/C) + (B/D)) * (1/A);
      
      v[2, 1] = w;
      v[3, 1] = t1;
      v[4, 1] = t2;
      v[2, 2] = W;
      v[3, 2] = T1;
      v[4, 2] = T2;
      
    } else if (w < t2) {
      A = t2 - t1;
      B = w - t1;
      C = t2 - w;
      D = b - t2;
      E = t1 - a;
      
      T1 = (2.0/3.0) * (1/E);
      T2 = (2.0/3.0) * (1/D);
      W = (2.0/3.0) * (1 - (B/E) - (C/D)) * (1/A);
      
      v[2, 1] = t1;
      v[3, 1] = w;
      v[4, 1] = t2;
      v[2, 2] = T1;
      v[3, 2] = W;
      v[4, 2] = T2;
    } else {
      A = b - t2;
      B = w - t2;
      C = t2 - t1;
      D = t1 - a;
      
      T2 = (2.0/3.0) * (1/C - 1/D);
      T1 = (2.0/3.0) * (1/D);
      W = (2.0/3.0) * (1 - (B/C) + (B/D)) * (1/A);
      
      v[2, 1] = t1;
      v[3, 1] = t2;
      v[4, 1] = w;
      v[2, 2] = T1;
      v[3, 2] = T2;
      v[4, 2] = W;
      
    }
    for (j in 1:N){
      f[j] = log(minpdf(y[j], v));
    }
    
    return (sum(f));  
    
  }
}


data{
  // parameters of distribution 1
  real a1;
  real b1;
  real t11;
  real t12;
  real w1;
  
  // parameters of distribution 2
  real a2;
  real b2;
  real t21;
  real t22;
  real w2;
  // parameters of distribution 3
  real a3;
  real b3;
  real t31;
  real t32;
  real w3; 
  
  int<lower=0> N; // number of observations
  real y[N]; // observations
  real<lower = 0> noy; //number of years
  real<lower = 2> u; // high threshold
  
  
  
}
parameters {
  real<lower = 0> qtilde1;
  real<lower = 0>  qtilde2;
  real<lower = 0>  qtilde3;
}
transformed parameters{
  real mu;
  real<lower = 0> nu = qtilde3 / qtilde2;
  real xi = log10(nu);
  real<lower = 0> sigma;
  sigma  = qtilde2 * xi / (nu * (nu - 1));
  mu = qtilde1 - qtilde2 / nu;
}
model {
  
  target += minknot(qtilde1|a1,b1,t11,t12,w1);
  target += minknot(qtilde2|a1,b1,t11,t12,w1);
  target += minknot(qtilde3|a1,b1,t11,t12,w1); 
  target += gpoispoint_lpdf(y | mu, xi, sigma,  u, noy) ;
  
}

And this is what I get when I try to check it:

> rstan:::rstudio_stanc("minknots.stan")
Error in stanc(filename, allow_undefined = TRUE) : 0
Semantic error in 'string', line 149, column 14 to column 47:
   -------------------------------------------------
   147:  model {
   148:  
   149:      target += minknot(qtilde1|a1,b1,t11,t12,w1);
                       ^
   150:      target += minknot(qtilde2|a1,b1,t11,t12,w1);
   151:      target += minknot(qtilde3|a1,b1,t11,t12,w1);
   -------------------------------------------------

A returning function was expected but an undeclared identifier 'minknot' was supplied.

I do not know how to find the error.

If you use the target += notation then you need to specify the full function name (minknot_lpdf)

You can only drop the _lpdf suffix if you use the ~ notation, like with Stan’s built-in distributions

Thanks for such a quick response. It enabled me to detect and correct another error, solving my problem.