stan-dev/stanc3

[BUG] Array literals in `return` statements may generate wrong type in C++

WardBrian opened this issue · 0 comments

Current Behavior:

A literal like { 0.0 } is always marked as DataOnly and generated as std::vector<double>, even when it is in a return position that requires the type to be autodiff.

This can lead to the C++ compiler to fail as a function which is meant to return std::vector<var> tries to return std::vector<double>

Model Code

functions {
  array[] real foo(real a) {
    return {0.1};
  }
}
parameters {
  real a;
}
model {
  array[1] real z = foo(a);
}

Environment:

stan 2.32.2

Anything else:

First noticed on forums: https://discourse.mc-stan.org/t/compilation-error-passes-syntax-check/32059