GLBasic forum

Main forum => Bug Reports => Topic started by: Moebius on 2011-Jul-28

Title: Calling a function in an extended type in an array
Post by: Moebius on 2011-Jul-28
...doesn't work if more than one 'symbol' is specified in the array's index.  The best way to describe this is with a few examples:

Code (glbasic) Select
// Extended type declaration...
TYPE ExtType

Var  // One variable...

FUNCTION Dummy:  // One function...
ENDFUNCTION

ENDTYPE

// Create the array...
LOCAL TypeArray[] AS ExtType
DIM TypeArray[1]

// Variables for demonstration:
LOCAL a = 0, b = 0, c = 0, d


d= TypeArray[0].Dummy() // Compiles
d= TypeArray[a].Dummy() // Compiles
d= TypeArray[a + b + c].Var // Compiles

d= TypeArray[0 + 0].Dummy() // Doesn't compile
d= TypeArray[ (0 + 0) ].Dummy() // Doesn't compile
d= TypeArray[0 * 0].Dummy() // Doesn't compile
d= TypeArray[a + b].Dummy() // Doesn't compile
d= TypeArray[ (a + b) ].Dummy() // Doesn't compile

KEYWAIT
END


The error produced is is "call to undefined function : ExtType".  You can quite easily get around it by using a temporary variable and passing that as the index, but seeing as this problem is specifically to do with functions in extended types, perhaps there's an only smallish code issue...
Title: Re: Calling a function in an extended type in an array
Post by: Kitty Hello on 2011-Jul-28
can you use ALIAS before the call? Maybe?
Code (glbasic) Select

ALIAS ptr AS TypeArray[0 + 0]
d= ptr.Dummy() // Doesn't compile


With expressions, my precompiler is very weak. I hope for the GLB-Script language to behave better, so I can use his error messages XD.
Title: Re: Calling a function in an extended type in an array
Post by: bigsofty on 2011-Jul-28
Simplest way around this is to make a temp var for any calculations that as used are parameters, ala...

Code (glbasic) Select
foo=a + b + c; d= TypeArray[foo].Var

Edit: Whoops I really should read all of the post...  :S