Jump to content
  • Advertisement
Sign in to follow this  
Sir Ementaler

Enum type conversion to int cost not calculated correctly.

This topic is 961 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

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() {

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() )

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
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!