• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code conditional expression is ambiguous

Hyomoto

Member
Using the new ternary operations I get this error during compile under these circumstances:
Code:
_rW = ( width != height ) ? ( _width / 2 ) : 0;
Code:
_alpha = ( _i == 0 ) ? 1 : alpha;
With the full error being:
error: conditional expression is ambiguous; 'YYRValue' can be converted to 'int' and vice versa

Is this a bug or am I stupid? The common theme is the value being called out is 0 and 1, while if I change the other values to both be non-variables, or I change the values to variables, then it works.
 
A

Ariak

Guest
I ran into a similar problem when testing the speed of the ternary operator vs if with a minumum function.
Code:
var a=-10;
if a<0 a=0;
a=(a<0) ? 0 : a ;
VM Compiling works just fine, but the YYC doesn't like the outvariable a also being part of the (true:false) statement.
 

Hyomoto

Member
This following work fine:
Code:
a = ( a == 0 ) ? 1 : 0
Code:
var _zero = 0, _one = 1;
a = ( a == 0 ) ? _one : _zero
Just not:
Code:
a = ( a == 0 ) ? _one : 0
From my experience it really only seems to care if the outputs are not the same, and I guess that's the ambiguity. For now it seems better to use an if statement.
 

Alice

Darts addict
Forum Staff
Moderator
You might want to report this one as a bug; I imagine the error being caused by the inner YYC compiler, especially if it's using a strictly typed language underneath. Either way, sounds like something that should be handled by YYG staff; I don't think it should be an error under normal circumstances.

(I imagine somewhere down the road, an expression like (a == 0) ? _one : 0 is produced, while it should probably be (a == 0) ? _one : (YYRValue)0 instead)
 

chirpy

Member
How do people work around this issue? I'm still seeing it when building YYC to x86 android emulators. Is "? :" buggy so we should just avoid using them?
 

Hyomoto

Member
@chirpy - The bug I was experiencing seems to have been fixed, and I haven't had this issue with compiling ternary operators anymore. However, they can still be a bit of a bother. The solution that has worked for me is to write the operators like this:
Code:
if ( a = b ? c : d ) { // do }
As long as I encapsulate the entire expression in (), I haven't had issues with it. However, I also haven't played with the Android export in a very long time. If it just refuses to work, you'll have to convert it back to it's conditional form and I'd suggest filing a bug report.
 
Top