Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stan parser: disallow transpose operator on primitive type variables #2594

Closed
mitzimorris opened this issue Jul 31, 2018 · 4 comments
Closed
Labels

Comments

@mitzimorris
Copy link
Member

Summary:

parser allows transpose of primitives in program - it would be better to flag this and fail.

Description:

noticed during code review as part of #2498

transpose is allowed to apply to a primitive, doing nothing. I'd rather it fail at this point and print a warning message, but that would be a change in current language behavior and we can do that in a different PR.

Reproducible Steps:

Please report steps to reproduce the issue. If it's not possible to reproduce, please include a description of how you discovered the issue.

If you have a reproducible example, please include it.

Current Output:

The current output. Knowing what is the current behavior is useful.

Expected Output:

Describe what you expect the output to be. Knowing the correct behavior is also very useful.

Additional Information:

Provide any additional information here.

Current Version:

v2.18.0

@VMatthijs
Copy link
Member

If I try to compile

model {
  print(1.0');
}

with stanc3, it tells me

Semantic error at file "test.stan", line 2, characters 8-12:
   -------------------------------------------------
     1:  model {
     2:    print(1.0');
                 ^
     3:  }
   -------------------------------------------------

Ill-typed arguments supplied to postfix operator '. Available signatures:
(matrix) => matrix
(row_vector) => vector
(vector) => row_vector
Instead supplied argument of incompatible type: real.

@bob-carpenter
Copy link
Member

bob-carpenter commented Dec 13, 2018 via email

@VMatthijs
Copy link
Member

Not an easy way, I think. Currently, start and end locations are only carried around for expressions, statements and identifiers. Operators do not fall into those categories. The error location currently being used is that of the expression 1.0' (specifically its start location).
I could consistently move the caret to the end rather than start of an expression in a semantic error, but I think that would make things worse, rather than better, overall.
Of course, these things can be fixed, but it's a matter of priorities.

@bob-carpenter
Copy link
Member

I think it's more conventional to point at the end of a problematic expression. Compare the C++ behavior:

int main() {
  double x = (x + x)++;
}

The error message is:

cpperr.cpp:2:21: error: expression is not assignable
  double x = (x + x)++;
             ~~~~~~~^
1 error generated.

And for this,

struct foo { };
int main() {
  foo y;
  double x = y++;
}

we get

cpperr.cpp:4:15: error: cannot increment value of type 'foo'
  double x = y++;
             ~^
1 error generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants