# Parser bug: Expected expression value

This topic is 2265 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Let's say I have a weird script which looks like this:

int main() { int some_value; if(some_value >= 3) int a=3; return 0; }

It should compile, but AngelScript throws me an error:
test.as (39, 2) : ERR: Expected expression value

I think this case is omitted in asCScriptNode *asCParser::ParseExprValue() method in as_parser.cpp.

Test was performed on HEAD revision of the AngelScript .

##### Share on other sites
I'll look into this. However, is the error message really from compiling that script? The error is reported for line 39, but there are obviously not 39 lines in the script.

Regards,
Andreas

##### Share on other sites
I rechecked the script, and I don't think it should compile. The error message should definitely be improved, but the problem here is the declaration of a variable in the if-case. That is not allowed.

The if condition must be followed by a statement or a statement-block, a variable declaration is not expected here.

You might argue the variable declaration should be allowed, but what is the point of allowing it, since it will immediately go out of scope after the initialization?

I'll make changes to improve the error message.

##### Share on other sites
I know that this code is useless (just as you mentioned) but our scripter used that code, to set breakpoint at some temporary place and he wrote that piece of code and that's how we found this error thing. In C++ that code compiles without any errors so I thinkg it should be also allowed in AngelScript even though it's useless (because of variable which immediately goes out of scope).

##### Share on other sites
C++ is more forgiving about user errors than I want AngelScript to be. It is actually a quite common bug in C++ to declare a local variable in an if-condition like this, but with the intention that the variable should live on beyond the scope of the condition. Usually you catch the problem when attempting to use the variable, but if the variable happen to have the same name as another in a higher scope it can be difficult to catch the error. By giving an error in the compiler I can avoid that common bug in AngelScript.

If there is a valid need to declare the variable like this then the declaration must be done within a statement block, i.e. between {}.

##### Share on other sites
Seems fair enough for me . Thanks!

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 14
• ### Forum Statistics

• Total Topics
632155
• Total Posts
3004477

×