Bug - Not A Bug Edge case where the wrong ASH function override is called

slyz

Developer
A strange bug Bale stumbled upon in his Adventure Advisor relay script. I could reduce the issue to the following code:
PHP:
# must be test(<something>, string)
void test( int something, string toprint )
{
	print( "test( string, string ) called" );
	print( "toprint = " + toprint );
}

# must have the same name as the function above
# (it must be an override)
void test( int whatever, int [int] m )
{
	print( "test( int, int [int] ) called" );
	test( whatever, "a string" );
}

int [int] any_map;
test( 2, any_map );
results in
Code:
> call test.ash

test( string, string ) called
toprint = aggregate int [int]
test( 2, any_map ) calls test(int, string) instead of test(int, int[int]).

I haven't had time to look at the source yet, but it sounds like fun one to track down.

Switching the order in which the test() functions are defined by adding
PHP:
void test( int whatever, int [int] m );
void test( int something, string toprint );
at the beginning of the code above fixes the issue.
 
Last edited:
Switching the order in which the test() functions are defined [...] at the beginning of the code above fixes the issue.

Really? That's nice to know, but so darn weird that mafia is not distinguishing between those datatypes under that circumstance.
 
Does it fix the issue, or just mean that the second (int, string) definition doesn't actually work? If you put in test(3,"testing") does that work or fail...?

Edit: Seems to fail.
Code:
# must have the same name as the function above 
# (it must be an override) 
void test( int whatever, int [int] m ) 
{ 
    print( "test( int, int [int] ) called" ); 
    test( whatever, "a string" ); 
} 

# must be test(<something>, string) 
void test( int something, string toprint ) 
{ 
    print( "test( string, string ) called" ); 
    print( "toprint = " + toprint ); 
} 

int [int] any_map; 
test( 2, any_map );  
test(3, "testing")
> call test

Function 'test( int, string )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (test.ash, line 6)
 
test( int, map ) calls test( int, string ), so the latter has the be defined before the former.

That error is why
PHP:
void test( int whatever, int [int] m ); 
void test( int something, string toprint );
has to be added before if you want to define the functions in a different order.
 
Last edited:
Back
Top