stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.02k stars 264 forks source link

Fix expose_stan_functions under Stanc 2.31 #1050

Closed andrjohns closed 1 year ago

andrjohns commented 1 year ago

Part of the expose_stan_functions_hacks code was replacing = nullptr with = 0, intended for the pstream__ = nullptr default argument. However this causes a compilation failure under 2.31, since the generated code now includes default template parameters with nullptr which are then replaced.

This PR updates the regex to only replace the nullptr if it's followed by a parenthesis - as the function definitions will always generate the pstream__ = nullptr as the last argument. I've also added a basic test.

This will also need to be backported to 2.26

andrjohns commented 1 year ago

I've also verified that this fixes the test failure for the prophet package under 2.31

hsbadr commented 1 year ago

Does this fix https://github.com/stan-dev/rstan/issues/954?

andrjohns commented 1 year ago

It's bizarre, I can't replicate the test failures locally under MacOS, Ubuntu, or Windows

andrjohns commented 1 year ago

Narrowed it down a bit more. The test will fail when run through rcmdcheck() but not when run through test_file()

andrjohns commented 1 year ago

Ah, it looks like sourceCpp-based functions aren't compatible with testthat, since it modifies include paths: https://stat.ethz.ch/pipermail/r-package-devel/2017q3/001951.html

May have to just remove the test entirely (after testing locally)

hsbadr commented 1 year ago

it looks like sourceCpp-based functions aren't compatible with testthat,

I see. Could probably use Catch: https://testthat.r-lib.org/reference/use_catch.html.

Anyway, it works on my local machine.