Ternary operators stopped paying attention to expected return type

Started by
5 comments, last by WitchLord 2 years, 5 months ago

I'm trying to update to 2.35.1 from a previous release, and a significant number of ternary operators in existing scripts are now broken. There's no way to rewrite the scripts, which have accumulated over a period of years. Is this intentional behavior, and if so, is there a setting somewhere (using asIScriptEngine::SetEngineProperty or similar) I can toggle to undo it?

Here are some trivial examples that no longer compile, instead citing “Can't find unambiguous implicit conversion to make both expressions have the same type.” It seems to me it should be unambiguous that the types are supposed to be converted to int:

int a = true ? 1 : 1.;
int a = true ? 1 : uint(1);
int a = true ? 1 : int16(1);

Similarly, this previously-fine code now fails with the errors “No default constructor for object of type 'foo'” and “No appropriate opAssign method found in 'foo' for value assignment."

class foo {
	foo(int){}
}
void main() {
	foo@ bar = true ? foo(0) : foo(0);
}

Without the ternary operator, i.e. foo@ bar = foo(0);, it compiles normally.

Advertisement

The ternary operators are evaluated before the use of the result, so the compiler does not know that ‘int’ is expected in these scenarios. However, I will look into the problem. Hopefully I'll find a solution that doesn't break backwards compatibility with 2.35.0.

Thanks for letting me know.

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 the first problem in rev 2750.

I'm still looking into the second problem.

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

The second problem has been fixed in rev 2751.

Can you try the latest WIP version and let me know if all your problems with the ternary operators have been fixed?

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 tried the latest WIP version, including the shared interface setting from the other topic, and I can happily report that all related scripts are compiling again now. Thanks a bunch!

Thanks for the confirmation of the fixes.

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