Sign in to follow this  
Sir Ementaler

Enum type conversion to int cost not calculated correctly.

Recommended Posts

Using one of the most recent revisions of AngelScript, one of our testers ran into a bug where the script was unable to pick the right overload for an enum type in the following circumstances:

enum e {val}
void f(int) {}
void f(int8) {}
void f(int16) {}
void f(int64) {}
void main() {
    f(val);
}

Essentially, neither of the int overloads is preferred by enum types (although signed int is preferred over unsigned). This was problematic, because our scripting interface exposes a method with a number of similar overloads that would ideally support any enum type, including user-defined ones. I was somewhat familiar with the way overload resolution works after research for my other recent report, which let me identify a likely source of the problem. The file as_compiler.cpp contains the following lines (beginning at line 5723 in our revision):

else if( to.GetSizeInMemoryBytes() || ctx->type.dataType.GetSizeInMemoryBytes() )
  cost = asCC_PRIMITIVE_SIZE_CONV;

I believe that the || operator in this part was actually intended to be !=, i.e. a size conversion is to be performed when two types differ in size. Modifying it seemingly fixed the issue on our side.

Share this post


Link to post
Share on other sites

I've fixed this in revision 2316. 

 

It wasn't quite as simple as your proposed solution. While that worked in your case, it caused problem in other cases when the compiler would have to chose between a function that takes an enum and another that takes an int.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this