Daniel commented on an issue that the code generator
was generating redundant braces:
There wasn’t an example, but I’m assuming he means something
like this:
transformed data {
real x;
{
real z;
z = 7;
}
}
model { }
( Sorry I don’t know how to add code formatting in Discourse through
email. )
This generates the following code:
try {
{
double z(0.0);
(void) z; // dummy to suppress unused var warning
…
stan::math::assign(z, 7);
}
} catch (const std::exception& e) {
stan::lang::rethrow_located(e,current_statement_begin__);
…
It looks like double braces are being generated, but what’s really
happending is that the body of the transformed data block is
as a whole put inside a try-catch statement. But the body as
a whole here is nothing more than a nested statement block, so you
get another stack of parens. They’re redundant, but avoiding
generating them would seriously mess up the clean(ish!)
recursive definitions.
Consider this minimal change to add a statement before the
nested statement block:
transformed data {
real x;
x = 5;
{
real z;
z = 7;
}
}
model { }
Now we get this and everything looks the way it should:
try {
current_statement_begin__ = 3;
stan::math::assign(x, 5);
{
double z(0.0);
…
}
} catch (const std::exception& e) {
stan::lang::rethrow_located(e,current_statement_begin__);
- Bob