Here's my cutdown code to show the problem
TYPE TypeA
A
B
ENDTYPE
TYPE TypeB
TypeAInstance AS TypeA
ENDTYPE
GLOBAL TypeBArray[] AS TypeB
FUNCTION DoStuff: Var1
X = RND(TypeBArray[Var1].TypeAInstance.A - TypeBArray[Var1].B)
ENDFUNCTION
The line of code
X = RND(TypeBArray[Var1].TypeAInstance.A - TypeBArray[Var1].B)
should be
X = RND(TypeBArray[Var1].TypeAInstance.A - TypeBArray[Var1].TypeAInstance.B)
If I try to compile it as follows where the first "TypeAInstance" is missing :-
X = RND(TypeBArray[Var1].A - TypeBArray[Var1].TypeAInstance.B)
The precompiler correctly sees that the code is incorrect :-
Quote
_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2009.013 - 2D, WIN32
"bb.gbas"(13) error : wrong argument type : TYPE TypeB has no member A
If however the first "TypeAInstance" is there but the
second type array is missing
ie.
X = RND(TypeBArray[Var1].TypeAInstance.A - TypeBArray[Var1].B)
Then the precompiler doesn't see the error. Instead, the compiler sees the error
Quote
_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2009.013 - 2D, WIN32
Wordcount:2 commands
compiling:
C:\DOCUME~1\shocking\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `DGInt __GLBASIC__::DoStuff(DGInt)':
C:\DOCUME~1\shocking\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:15: error: 'class __GLBASIC__::TypeB' has no member named 'B'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.0 sec. Time: 12:53
Build: 0 succeeded.
*** 1 FAILED ***
If both the first and second "TypeAInstance" are missing, the precompiler sees that the first is missing and errors.
This code:
TypeBArray[Var1].B)
Gives this error:
"bb.gbas"(13) error : wrong argument type : TYPE TypeB has no member A
You wanted to write
TypeBArray[Var1].TypeAInstance.B)
Hi Gernot,
I realise that the "TypeAInstance" was missing - what I tried to explain was that the precompiler isn't picking up errors it should. My point is that if I had on the one line of code
... TypeBArray[Var1].TypeAInstance.B ... TypeBArray[Var1].B ...
then the PREcompiler wouldn't pick up the missing "TypeAInstance" at the end of the line. If the code was
... TypeBArray[Var1].B ...
then the precompiler sees there's a problem (ie. the precompiler only sees the first array on the line) - if it's the second then the precompiler doesn't see anything wrong with the line of code. It only gets picked up by the "compiler" at the end of the compile step.
I hope that explains it well enough.
Yes, you're right. The precompiler is not very good with TYPE name checking. I'll have to build a whole system to fix this, soon.
A different fault with arrays of types :-
If you have a 2 dimensional array of a type, eg.
type MyType
VarA
VarB
endtype
global MyArray[] as MyType
Redim MyArray[5][5]
-------------
Then you try to assign to the array and forget to specify the type field, you get a compiler (but not precompiler) error
eg.
MyArray[1][2]=10
Gives an error like :-
Quotegpc_temp4.cpp:5: error: no match for 'operator=' in '(&__GLBASIC__::MyArray)->__GLBASIC__::DGArray<T>::operator() [with T = __GLBASIC__::MyType](#`fix_trunc_expr' not supported by dump_expr#<expression error>, #`fix_trunc_expr' not supported by dump_expr#<expression error>) = 10'
Obviously the code should've been either "MyArray[1][2].VarA" or ""MyArray[1][2].VarB". The fact that the precompiler doesn't pick up that it's missing is the fault.
you dont know much about types in GLBasic right?
That can't work:
MyArray[1][2]=10 // have no member selected to put the 10 in!
its must be:
MyArray[1][2].VarA = 10
MyArray[1][2].VarB = 20
for the rest:
Quote from: Kitty Hello on 2009-Apr-21
Yes, you're right. The precompiler is not very good with TYPE name checking. I'll have to build a whole system to fix this, soon.
close