diff --git a/src/stan/lang/ast/fun/has_var_vis_def.hpp b/src/stan/lang/ast/fun/has_var_vis_def.hpp index 9e6469069d4..de3cb140805 100644 --- a/src/stan/lang/ast/fun/has_var_vis_def.hpp +++ b/src/stan/lang/ast/fun/has_var_vis_def.hpp @@ -47,7 +47,7 @@ namespace stan { bool has_var_vis::operator()(const variable& e) const { scope var_scope = var_map_.get_scope(e.name_); return var_scope.par_or_tpar() - || (var_scope.is_local() && !e.type_.base_type_.is_int_type()); + || (var_scope.local_allows_var() && !e.type_.base_type_.is_int_type()); } bool has_var_vis::operator()(const fun& e) const { diff --git a/src/stan/lang/ast/scope.hpp b/src/stan/lang/ast/scope.hpp index 36476d34ea6..82b8afd4ea5 100644 --- a/src/stan/lang/ast/scope.hpp +++ b/src/stan/lang/ast/scope.hpp @@ -65,6 +65,16 @@ namespace stan { */ bool is_local() const; + /** + * Flags local scopes which permit parameter variables. + * Allows local blocks in functions, transfromed parameter, + * and model blocks; disallows local blocks in transformed data + * and generated quantities program blocks. + * + * @return true for local parameter origin block types + */ + bool local_allows_var() const; + /** * Flags scopes where parameter variables are declared, * i.e., top-level of parameter or transformed parameter block. diff --git a/src/stan/lang/ast/scope_def.hpp b/src/stan/lang/ast/scope_def.hpp index 8dd11856956..95364cc64b6 100644 --- a/src/stan/lang/ast/scope_def.hpp +++ b/src/stan/lang/ast/scope_def.hpp @@ -25,6 +25,12 @@ namespace stan { return is_local_; } + bool scope::local_allows_var() const { + return is_local_ + && program_block_ != transformed_data_origin + && program_block_ != derived_origin; + } + bool scope::par_or_tpar() const { return !is_local_ && (program_block_ == parameter_origin diff --git a/src/stan/lang/ast/sigs/function_arg_type.hpp b/src/stan/lang/ast/sigs/function_arg_type.hpp index b940af676f5..fcefc34a8b0 100644 --- a/src/stan/lang/ast/sigs/function_arg_type.hpp +++ b/src/stan/lang/ast/sigs/function_arg_type.hpp @@ -60,7 +60,7 @@ namespace stan { /** * Return true if the `expr_type` of the specified * `function_arg_type` is not equal to the - * `expr_type` of this `function_arg_type