Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ksvanhorn opened this issue Aug 28, 2018 · 5 comments
Assignees
Milestone

Comments

@ksvanhorn
Copy link
Contributor

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

@bob-carpenter
Copy link
Contributor

Definitely a bug in the error message. We should be able to reuse the same term for a function name and variable, too. We'll look into it and fix. Thanks for reporting.

@VMatthijs
Copy link
Member

Stanc3 now says

Semantic error at file "test.stan", line 8, characters 7-10:
   -------------------------------------------------
     6:  data { int<lower=0> N; vector[N] y; }
     7:  parameters {
     8:    real foo;
                ^
     9:  }
    10:  model {
   -------------------------------------------------

Identifier  foo  is already in use.

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Dec 13, 2018 via email

@VMatthijs
Copy link
Member

Thanks for the feedback! I agree. I've fixed points 1-3 in stanc3.

@mitzimorris mitzimorris modified the milestones: 2.18.1, 2.18.1++ Dec 23, 2018
@seantalts seantalts modified the milestones: 2.18.1++, 2.19.0++ Mar 20, 2019
@mcol
Copy link
Contributor

mcol commented Feb 25, 2020

Current message is:

Semantic error in 'test.stan', line 8, column 7 to column 10:
   -------------------------------------------------
     6:  data { int<lower=0> N; vector[N] y; }
     7:  parameters {
     8:    real foo;
                ^
     9:  }
    10:  model {
   -------------------------------------------------

Identifier 'foo' is already in use.

@mcol mcol closed this as completed Feb 25, 2020
@mcol mcol modified the milestones: 2.22.0++, 2.22.0 Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants