Jump to content
  • Advertisement
Sign in to follow this  
virious

Parser bug: Expected expression value

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

If you intended to correct an error in the post then please contact us.

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 smile.png.

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!