[Gambas-user] Issue 194 in gambas: "IIf" is buggy

gambas at ...2524... gambas at ...2524...
Wed Jan 18 23:22:17 CET 2012


Status: New
Owner: ----
Labels: Version Type-Bug Priority-Medium OpSys-Any Dist-Any Arch-Any  
Desktop-Any GUI-Any

New issue 194 by emil.len... at ...626...: "IIf" is buggy
http://code.google.com/p/gambas/issues/detail?id=194

1) Describe the problem.
IIf does not do the correct job when the true part and false part are of  
different types.

2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):

Version: TRUNK
Revision: r4404

3) Provide a little project that reproduces the bug or the crash.
   Dim i As Integer
   For i = 1 To 2
     Print Int(IIf(i = 1, 1.0, 1))
   Next

5) Explain clearly how to reproduce the bug or the crash.
Running the code above prints out
1
0
when
1
1
is expected. This is due to that first time IIf returns a Float, but second  
time an Integer. IIf should convert the return value to the one that  
SUBR_check_good_type returns or something..., that is almost already  
implemented ;)

This is the current code:

void SUBR_if(ushort code)
{
	TYPE type;
   SUBR_ENTER_PARAM(3);

   VALUE_conv_boolean(PARAM);

	switch (code & 0x1F)
	{
		case 0:
		
			type = SUBR_check_good_type(&PARAM[1], 2);
			if (type != T_VARIANT)
			{
				*PC |= 1;
				goto __TYPE;
			}
			else
			{
				*PC |= 2;
				goto __VARIANT;
			}
		
		case 1:
		__TYPE:
		
			*RETURN = PARAM->_boolean.value ? PARAM[1] : PARAM[2];
			
			break;
			
		case 2:
		__VARIANT:
		
			if (PARAM->_boolean.value)
			{
				VALUE_conv_variant(&PARAM[1]);
				*RETURN = PARAM[1];
			}
			else
			{
				VALUE_conv_variant(&PARAM[2]);
				*RETURN = PARAM[2];
			}
			
			break;
	}

   SUBR_LEAVE();
}





More information about the User mailing list