nimble
nimble copied to clipboard
setup outputs in only one branch of an if can confuse a programmer
Not really an issue per se, so we may want to close this after a bit of discussion, but in working with Claudia, this came up:
In setup code, suppose one has:
if(foo) {
x <- bar
} else {
# don't define x
}
Then in run code:
if(foo) {
tmp <- 2*x # use x
} else {
# don't use x
}
If the nimbleFunction is specialized such that foo is FALSE, there is a compilation error in trying to find 'x'.
Error in get(.var_unique_name_1415927) :
object 'x' not found
This is the sort of thing that requires a programmer to understand a bit about variables being defined in C++. We could say something about this in the manual in Section 14.3 but it's likely to be overlooked. Or I suppose we could expand the error message to suggest common cases that lead to the error.
Not sure whether there is a good 'solution' to this, but I think it's an example of the types of things that could cause a new NIMBLE programmer to get frustrated.