alashworth / test-issue-import

0 stars 0 forks source link

tighter typing on local variables #166

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by bob-carpenter Monday Sep 11, 2017 at 10:51 GMT Originally opened as https://github.com/stan-dev/stan/issues/2395


Summary:

Right now, local variables are promoted to the return type of a function or the type of a block. But if they're data variables, this overpromotes.

Description:

We could lean lean on the data qualifiers in function declaration to help know that variables can safely be double or int.

Reproducible Steps:

For example,

real foo(real x, real y, real z) {
  real a = y^2 + z^2;

will declare the local variable for a using the return type of the function, which is the promotion of all three types, not just y's and z's.

Same situation with

model {
  real a = y^2 + z^2;

If y and z are data variables, then a can be declared as double.

Current Version:

v2.17.0

alashworth commented 5 years ago

Comment by VMatthijs Thursday Dec 13, 2018 at 13:04 GMT


@seantalts , this might interest you. This information should be statically available in the decorated ast in stanc3.