Enum type conversion to int cost not calculated correctly.

Started by
1 comment, last by WitchLord 8 years ago

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.

Advertisement

I'll investigate this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement