-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Bad line numbers when exceptions thrown in if/then tests #1990
Comments
Yes, it's only when the exceptions come from the checks themselves. That one's hard to fix, because only the statements have line numbers attached to them and the conditional expressions aren't statements. You can see that in the generated code where there are line number increment statements everywhere (it's a rather crude and run-time intensive solution). And the if-then is one big statement; there isn't a statement to execute if the first conditional expression fails in an if-else. I could update the messages so they indicated a range of line numbers because I store the start and ending line for a statement---that might be less confusing. |
That would be a reasonable solution. It’s just confusing On Aug 25, 2016, at 2:20 PM, Bob Carpenter [email protected] wrote:
|
here is the generated code for the 2nd example:
in order to make this fly, the parser would have to capture the start and end lines of the
doable, but a real PITA when working in the boost::spirit::qi parser. |
That's still not quite enough if it ends in the middle of an else if.
The problem is that there's no hook within the body to increment before evaluating
In general, |
cool! |
Observe that this even happens with static errors, rather than runtime errors. For example, on the ill-formed model
stanc2 says
Instead, stanc3 now says
I hope we can also translate this into a better error location for runtime errors. |
That's great. We never got line number identifiers for expressions going everywhere, so couldn't isolate the error in stanc2.
… On Dec 13, 2018, at 8:14 AM, Matthijs Vákár ***@***.***> wrote:
Observe that this even happens with static errors, rather than runtime errors. For example, on the ill-formed model
parameters {
real x;
}
model {
x ~ normal(0, 1);
}
generated quantities {
real y;
if (x < 0) {
y = x;
} else if ({1,2}) {
y = -x;
}
}
stanc2 says
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Conditions in if-else statement must be primitive int or real; found type=int[ ]
error in 'stan/src/test/test-models/good/empty.stan' at line 11, column 14
-------------------------------------------------
9: generated quantities {
10: real y;
11:
^
12: if (x < 0) {
-------------------------------------------------
PARSER EXPECTED: <expression>
Instead, stanc3 now says
Semantic error at file "test.stan", line 14, characters 13-18:
-------------------------------------------------
12: if (x < 0) {
13: y = x;
14: } else if ({1,2}) {
^
15: y = -x;
16: }
-------------------------------------------------
Condition in conditional needs to be of type int or real. Instead found type int[].
I hope we can also translate this into a better error location for runtime errors.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Fixed with stanc3. Closing. |
Description:
When exceptions are thrown in the logic of if/then statements the line number points to the first if statement and not the actual line where the exception was encountered.
Reproducible Steps:
The behavior is the same without the braces, too,
Current Output:
Expected Output:
The exception is thrown at line 14. Line 12 is where the if statement begins.
Additional Information:
Exceptions thrown within the body of the if/then statements report accurate line numbers. It just seems to be when the exceptions are thrown in the checks themselves.
Current Version:
Develop.
The text was updated successfully, but these errors were encountered: