How does Stan count lines

I have a very simple question: how does Stan count lines for its error messages? Now, the question might seem straightforward, however I keep getting error messages with reference to line where there is no code or that are clearly not the line with a coding error. So it is clear that Stan does not count lines form the start of the Stan file (where I usually put comment lines describing what the model does). I then thought it started counting from the first line of actual code, but I still get weird line references for errors. For example, in this piece of code, what is the line number for y? Is it line 10 or 3 or something else?

// Author: Myself
// Date: Feb 2023
// This model is a model


////////////////////////////////////////////////////////////////////////////////

data {
  int<lower=0> N;          
  vector[N] y;                 
  vector[N] se;               
}
2 Likes

It is line 10. For example, if I introduce an error by renaming the variable to 0y (an invalid name) I get this error:

Syntax error in 'test.stan', line 10, column 12 to column 13, parsing error:
   -------------------------------------------------
     8:  data {
     9:    int<lower=0> N;
    10:    vector[N] 0y;
                     ^
    11:    vector[N] se;
    12:  }
   -------------------------------------------------

We expect to see an identifier after a sized type.

So you are saying that it starts counting from the first line of the document correct? This does not explain, though, why so many times I get weird line numbers.

Correct. If you have an example which consistently produces the incorrect error, that would most likely indicate a bug