-
-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
Labels
Description
Consider two stan programs:
prog1:
transformed parameters {
target += 1;
}prog2:
functions {
void foo_lp(real x){
target += x;
}
}
transformed parameters {
foo_lp(1);
}prog1. stan produces a type error:
Semantic error in 'prog1.stan', line 2, column 3 to column 15:
-------------------------------------------------
1: transformed parameters {
2: target += 1;
^
3: }
-------------------------------------------------
Target can only be accessed in the model block or in definitions of functions with the suffix _lp.
prog2.stan compiles just fine.
This is because we have this check for target+= statements:
stanc3/src/frontend/Semantic_check.ml
Lines 1112 to 1113 in 095b8ef
| let semantic_check_target_pe_usage ~loc ~cf = | |
| if cf.in_lp_fun_def || cf.current_block = Model then Validate.ok () |
And this check for the calling of _lp functions:
stanc3/src/frontend/Semantic_check.ml
Lines 238 to 246 in 095b8ef
| let semantic_check_fn_target_plus_equals cf ~loc id = | |
| Validate.( | |
| if | |
| String.is_suffix id.name ~suffix:"_lp" | |
| && not | |
| ( cf.in_lp_fun_def || cf.current_block = Model | |
| || cf.current_block = TParam ) | |
| then Semantic_error.target_plusequals_outisde_model_or_logprob loc |> error | |
| else ok ()) |
Reactions are currently unavailable