Skip to content

Misleading error message when function multiply defined #2526

@bob-carpenter

Description

@bob-carpenter

From @ksvanhorn on May 25, 2018 16:47

Summary:

When a function is defined twice, the error message points to the function AFTER the second definition.

Description:

A program defines the function "rot_matrix" twice in the "functions" block. The error message points at the beginning of the definition of a later function, "scale_matrix".

Reproducible Steps:

Run stanc on the following program:

functions {
  matrix rot_matrix() {
    return rep_matrix(0,1,1);
  }
  
  matrix rot_matrix() {
    return rep_matrix(0,1,1);
  }
  
  matrix scale_matrix() {
    return rep_matrix(0,1,1);
  }
}
data {
  int<lower = 1> N;
  vector[N] y;
}
parameters {
  real<lower=0> sigma;
}
model {
  sigma ~ normal(0, 1);
  y ~ normal(0, sigma);
}     

Current Output:

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

Parse Error.  Function already defined, name=rot_matrix  error in 'model661b1902a01a_foo' at line 10, column 3
  -------------------------------------------------
     8:   }
     9:   
    10:   matrix scale_matrix() {
          ^
    11:     return rep_matrix(0,1,1);
  -------------------------------------------------
 
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'foo' due to the above error. 

Expected Output:

The caret should point at the beginning of the second definition of rot_matrix.

RStan Version:

2.17.3

R Version:

R version 3.4.3 (2017-11-30)

Operating System:

OS X 10.13.4

Copied from original issue: stan-dev/rstan#533

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions