[3.2 RC5] Compiler failure at calling static func inside [ ]

Started by Crimson Wizard, Thu 08/07/2010 18:34:33

Previous topic - Next topic

Crimson Wizard

Example code:

Code: ags

struct MyStruct
{
  import static int func();
};

function SomeOtherFunc()
{
   int arr[100];
   int var = arr[MyStruct.func()];    // <--- line X
}


Compiler stops with error: " Error (line X): parse error after '[' ".


Possible workaround:
Code: ags

   int dummy = MyStruct.func();
   int var = arr[dummy];


Khris

I didn't test this and the error seems unrelated, but doesn't an array declaration require a constant?
What happens if you try this using a dynamic array?

Crimson Wizard

Quote from: Khris on Thu 08/07/2010 18:51:18
I didn't test this and the error seems unrelated, but doesn't an array declaration require a constant?
What happens if you try this using a dynamic array?
It isn't array declaration. It is getting array's element by index.

There's no error if a non-static struct member is used.
I guess it is parsing mistake.

Monsieur OUXX

#3
Yeah, I've noticed that the compiler sometimes doesn't really like complex expressions between the square brackets of an array.
The few times it happend, as you already mentionned, I used the workaround to use a temporary variable :

temporary variable : = complex expression
array[temporary variable] : =   ...
 

Khris

Yeah, sorry, I have to stop posting here while being too tired =)

Crimson Wizard

Quote from: Monsieur OUXX on Fri 09/07/2010 11:03:28
temporary variable : = complex expression
array[temporary variable] : =   ...

Pascal coder detected  ;D

Pumaman

Yes, there are a couple of limitations on the way the compiler handles static functions & properties. It's the same reason that this doesn't work:

int hour = DateTime.Now.Hour;

I will try to get around to fixing it at some point.

SMF spam blocked by CleanTalk