• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Discussion Are function argument types ever validated?

Kahenraz

Landlubber
This was a surprise. Are the argument types of declarations purely decoration? As far as I can tell, they are never tested by the parser.

Note that this example has no runtime errors and every argument is effectively an "int" regardless of the type actually specified by the function definition:

Code:
void testFuncTypes(bool a, int b, float c, string d, object e, ref f, aref g) {
   a = 123;
   b = 123;
   c = 123;
   d = 123;
   e = 123;
   f = 123;
   g = 123;
   
   trace("bool : " + a);
   trace("int : " + b);
   trace("float : " + c);
   trace("string : " + d);
   trace("object : " + e);
   trace("ref : " + f);
   trace("aref : " + g);
}

void ExecuteConsole()
{
   int num = 0;
 
   testFuncTypes(num, num, num, num, num, num, num);
}

I would seem that argument types are merely a form of type "hinting" that is required, never validated, and therefore may end up providing the wrong information when used as a reference.
 
Last edited:
Indeed the system does not seem to rigorously check that an argument declared as a certain type in a function definition is supplied with the correct type by the function call, and this has led to some bugs in the game which were hard to track down. Sometimes you'll see functions which copy the argument into a local variable of the correct type, then use that variable rather than the argument itself. This forces the argument value into the correct type.

The system does not always even check that the correct number of arguments are present. For example:
Unconfirmed Bug - Mutiny problem
 
Are the argument types of declarations purely decoration? As far as I can tell, they are never tested by the parser.
That sounds about right,yes.
This game's PROGRAM code can have some pretty wondrous effects at times... :rofl

I still remember one time where one specific line of code was CURSED.
Whatever I put on that line, I wouldn't do what I wanted it to.
So I put something nonsensical on that line which did absolutely nothing, then put the actual code I wanted to run on the next line.
Somehow this worked. o_O

You can still find this in PROGRAM\Loc_ai\LAi_fightparams.c:
Code:
    bool noExp;       // PB: Whatever is on this line ends up changing from what you set. Positively BIZARRE behaviour!
    noExp = false;   // Baste: So we set it to false on THIS line instead
The code has changed A LOT since then so for all I know this might no longer be a problem.
But at the time... well... you can tell what I think of it from my still-remaining comment there... :diomed
 
Back
Top