Skip to content

Incorrect error message when same identifier used for both fct name and var name #2621

@ksvanhorn

Description

@ksvanhorn

Summary:

When the same identifier is used for both a fct name and var name, it misidentifies this as use of a reserved word.

Description:

I use "foo" as the name of a function in the functions block. Then I also use it as a parameter name in the parameters block. The error message says "variable identifier (name) may not be a reserved word", but "foo" is not a reserved word.

Reproducible Steps:

code <- '
functions {
  real foo(real x) {
    return 2.0 * x;
  }
}
data { int<lower=0> N; vector[N] y; }
parameters {
  real foo;
}
model {
  y ~ normal(foo, 1);
}
'
library(rstan)
sm <- stan_model(model_code = code)

Current Output:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

variable identifier (name) may not be reserved word
    found identifier=foo
  error in 'model1219268b0a499_bf344b66bb761e274281c4862a3bdfdd' at line 9, column 7
  -------------------------------------------------
     7: data { int<lower=0> N; vector[N] y; }
     8: parameters {
     9:   real foo;
              ^
    10: }
  -------------------------------------------------

PARSER EXPECTED: <identifier>
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'bf344b66bb761e274281c4862a3bdfdd' due to the above error.

Expected Output:

I expect it to complain that "foo" is already being used as the name of a function.

Additional Information:

Current Version:

v2.17.3

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions