Skip to content

array constructors don't work with sampling statements #2710

@bob-carpenter

Description

@bob-carpenter

Summary:

This file should compile:

parameters {
  real<lower = 0> sigma;
}
model {
  sigma ~ inv_gamma(1e-4, 1e-4);
  { -1.0, 0.0, 1.0 } ~ normal(0, sigma);
}

Instead, I get

SYNTAX ERROR, MESSAGE(S) FROM PARSER:

Illegal statement beginning with non-void expression parsed as
  -(1.0)
Not a legal assignment, sampling, or function statement.  Note that
  * Assignment statements only allow variables (with optional indexes) on the left;
  * Sampling statements allow arbitrary value-denoting expressions on the left.
  * Functions used as statements must be declared to have void returns

  error in 'model416374d59793_bad_gamma' at line 6, column 5
  -------------------------------------------------
     4: model {
     5:   sigma ~ inv_gamma(1e-4, 1e-4);
     6:   { -1.0, 0.0, 1.0 } ~ normal(0, sigma);
            ^
     7: }
  -------------------------------------------------

PARSER EXPECTED: "}"
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'bad-gamma' due to the above error.n

As an aside, it works if the array constructor is replaced with a vector constructor, [ -1.0, 0.0, 1.0 ].

Current Version:

v2.18.0

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.18.1       StanHeaders_2.18.0 ggplot2_2.2.1     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18       magrittr_1.5       munsell_0.4.3      colorspace_1.3-2  
 [5] R6_2.2.2           rlang_0.2.1        plyr_1.8.4         tools_3.5.0       
 [9] parallel_3.5.0     pkgbuild_1.0.2     grid_3.5.0         gtable_0.2.0      
[13] loo_2.0.0          cli_1.0.0          matrixStats_0.54.0 lazyeval_0.2.1    
[17] assertthat_0.2.0   tibble_1.4.2       crayon_1.3.4       processx_3.2.0    
[21] gridExtra_2.3      callr_3.0.0        codetools_0.2-15   base64enc_0.1-3   
[25] ps_1.2.0           inline_0.3.15      compiler_3.5.0     pillar_1.2.3      
[29] scales_0.5.0       prettyunits_1.0.2  stats4_3.5.0      

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions