-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
This is a continuation of the discussion with @WardBrian here: #995 (comment)
Long story short, this model's generated code fails to compile:
transformed data {
real multiply;
real a = multiply(0, 1);
}with
examples/test/test.hpp: In constructor ‘test_model_namespace::test_model::test_model(stan::io::var_context&, unsigned int, std::ostream*)’:
examples/test/test.hpp:66:24: error: expression cannot be used as a function
66 | a = multiply(0, 1);
| ^
We allow shadowing and it works with nullary and unary functions. For example this model works fine:
transformed data {
real log;
real a = log(10);
real e;
real f = e();
real positive_infinity;
real g = positive_infinity();
}
Solutions to this are:
a) add stan::math namespace to a function if there is a variable with the same name used in the model
b) add stan::math namespace to all Stan Math function calls (this probably doesnt work as we may fallback to std:: in some cases)
c) if a function is shadowed it can no longer be used as a function in that model (@WardBrian mentioned this is what Python does)
d) disallow shadowing for binary functions (we have to check functions with 3+ args as well)
This is not a new issue for this release, its been present since we allowed shadowing.